Java Code Examples for com.rabbitmq.client.QueueingConsumer#nextDelivery()

The following examples show how to use com.rabbitmq.client.QueueingConsumer#nextDelivery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RabbitMqManager.java    From AuTe-Framework with Apache License 2.0 6 votes vote down vote up
@Override
public Message waitMessage(String queueName, Long timeoutMs, String testIdHeaderName, String testId) throws JMSException {
    try {
        Channel channel = senderConnection.createChannel();
        final QueueingConsumer consumer = new QueueingConsumer(channel);
        channel.basicConsume(queueName, true, consumer);

        QueueingConsumer.Delivery delivery = consumer.nextDelivery(timeoutMs);
        if (delivery != null) {
            channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
            RMQTextMessage message = new RMQTextMessage();
            message.setText(new String(delivery.getBody()));
            return message;
        }
        return null;
    } catch (IOException | InterruptedException e) {
        log.error("RabbitMQ waitMessage error: {}", e);
    }
    return null;
}
 
Example 2
Source File: RabbitConsumer.java    From java-study with Apache License 2.0 6 votes vote down vote up
public static void main(String[] argv) throws Exception {

	    ConnectionFactory factory = new ConnectionFactory();
	    factory.setHost("127.0.0.1");
	   // 打开连接和创建频道,与发送端一样  
	    Connection connection = factory.newConnection();
	    Channel channel = connection.createChannel();
	 // 声明队列,主要为了防止消息接收者先运行此程序,队列还不存在时创建队列。  
	    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
	    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
	  // 创建队列消费者  
	    QueueingConsumer consumer = new QueueingConsumer(channel);
	    // 指定消费队列
	    channel.basicConsume(QUEUE_NAME, true, consumer);
	    while (true) {  //消费者程序运行开着 如果生产者新增了数据会自动获取
	      Thread.sleep(500);
	    	 // nextDelivery是一个阻塞方法(内部实现其实是阻塞队列的take方法)  
	      QueueingConsumer.Delivery delivery = consumer.nextDelivery();
	      String message = new String(delivery.getBody());
	      System.out.println("'[x] Received '" + message );
  }   
  }
 
Example 3
Source File: AMQPContConsumer.java    From reactive with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	Channel channel = AMQPCommon.connect();
	QueueingConsumer consumer = new QueueingConsumer(channel);
	channel.basicQos(1);
	channel.basicConsume("trade.eq.q", false, consumer);

	while (true) {
		QueueingConsumer.Delivery msg = consumer.nextDelivery();
		System.out.println("received: " + new String(msg.getBody()));
		Thread.sleep(2000);
		channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
	}			
}
 
Example 4
Source File: AMQPWorkflowProcessor.java    From reactive with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public void execute() throws Exception {
	Channel channel = AMQPCommon.connect();
	QueueingConsumer consumer = new QueueingConsumer(channel);
	channel.basicConsume("workflow.q", true, consumer);

	while (true) {
		QueueingConsumer.Delivery message = consumer.nextDelivery();
		String msg = new String(message.getBody());
		System.out.println("received: " + msg);
		String newMsg = msg.substring(0, msg.indexOf(" shares"));
		byte[] bmsg = newMsg.getBytes();
		System.out.println("Trade fixed: " + newMsg);
		channel.basicPublish("", "trade.eq.q", null, bmsg);
	}			
}
 
Example 5
Source File: AMQPConfig.java    From reactive with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public void execute() throws Exception {
	Channel channel = AMQPCommon.connect();
	QueueingConsumer consumer = new QueueingConsumer(channel);
	channel.basicConsume("config.q", true, consumer);

	//cleanup any left over messages before continuing...
	while (true) {
		if (consumer.nextDelivery(1000) == null) break;
		System.out.print(".");
	}
	
	System.out.println("");		
	System.out.println("place_trade_low:     - (-)");
	System.out.println("place_trade_current: 2000 (1000) <==");
	System.out.println("place_trade_high:    - (-)");
	System.out.println("");
	
	while (true) {
		QueueingConsumer.Delivery message = consumer.nextDelivery();
		String msg = new String(message.getBody());
		String[] values = msg.split(",");
		long low = new Long(values[0]);
		long cur = new Long(values[1]);
		long high = new Long(values[2]);
		//message in low,med,high format (duration)
		System.out.println("place_trade_low:     " + low*2 + " (" + low + ")");
		System.out.println("place_trade_current: " + cur*2 + " (" + cur + ") <==");
		System.out.println("place_trade_high:    " + high*2 + " (" + high + ")");
		System.out.println("");
	}			
}
 
Example 6
Source File: RabbitEc2LiveTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Override
protected void doTest(Location loc) throws Exception {
    RabbitBroker rabbit = app.createAndManageChild(EntitySpec.create(RabbitBroker.class));
    rabbit.start(ImmutableList.of(loc));
    EntityAsserts.assertAttributeEqualsEventually(rabbit, RabbitBroker.SERVICE_UP, true);

    byte[] content = "MessageBody".getBytes(Charsets.UTF_8);
    String queue = "queueName";
    Channel producer = null;
    Channel consumer = null;
    try {
        producer = getAmqpChannel(rabbit);
        consumer = getAmqpChannel(rabbit);

        producer.queueDeclare(queue, true, false, false, Maps.<String,Object>newHashMap());
        producer.queueBind(queue, AmqpExchange.DIRECT, queue);
        producer.basicPublish(AmqpExchange.DIRECT, queue, null, content);
        
        QueueingConsumer queueConsumer = new QueueingConsumer(consumer);
        consumer.basicConsume(queue, true, queueConsumer);
    
        QueueingConsumer.Delivery delivery = queueConsumer.nextDelivery();
        assertEquals(delivery.getBody(), content);
    } finally {
        if (producer != null) producer.close();
        if (consumer != null) consumer.close();
    }
}
 
Example 7
Source File: Dispatcher.java    From reactive with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public void dispatchMessages() throws Exception {
	Channel channel = AMQPCommon.connect();
	QueueingConsumer consumer = new QueueingConsumer(channel);
	channel.basicQos(1);
	channel.basicConsume("trade.eq.q", false, consumer);

	java.util.Scanner input = new java.util.Scanner(System.in);
    System.out.print("Display Allocation Map? (y/n): ");
    display = input.next().equalsIgnoreCase("y");
	input.close();
	
	//start with 5 threads...
	for (long i=1;i<6;i++) {
		TradeProcessor processor = new TradeProcessor(this, i);
		threadpool.put(i, processor);
		processingCountMap.put(i, 0L);
		new Thread(()->processor.start()).start();
	}

	displayAllocationMap();
	while (true) {
		QueueingConsumer.Delivery msg = consumer.nextDelivery();
		channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
		String trade = new String(msg.getBody());
		String context = getContext(trade);
		Long threadId = 0L;
					
		if (allocationMap.containsKey(context)) {
			threadId = allocationMap.get(context);
		} else {
			threadId = getNextAvailableThread();
			allocationMap.put(context, threadId);
		}
		processingCountMap.put(threadId, processingCountMap.get(threadId)+1);
		if (display) System.out.println("Dispatcher: Received " + trade);
		displayAllocationMap();
		threadpool.get(threadId).addMessage(new String(msg.getBody()));				
	}			
}
 
Example 8
Source File: RabbitIntegrationTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
/**
 * Test that an AMQP client can connect to and use the broker.
 */
@Test(groups = {"Integration", "WIP"})
public void testClientConnection() throws Exception {
    rabbit = app.createAndManageChild(EntitySpec.create(RabbitBroker.class));
    rabbit.start(ImmutableList.of(testLocation));
    EntityAsserts.assertAttributeEqualsEventually(rabbit, Startable.SERVICE_UP, true);

    byte[] content = "MessageBody".getBytes(Charsets.UTF_8);
    String queue = "queueName";
    Channel producer = null;
    Channel consumer = null;
    try {
        producer = getAmqpChannel(rabbit);
        consumer = getAmqpChannel(rabbit);

        producer.queueDeclare(queue, true, false, false, ImmutableMap.<String,Object>of());
        producer.queueBind(queue, AmqpExchange.DIRECT, queue);
        producer.basicPublish(AmqpExchange.DIRECT, queue, null, content);
        
        QueueingConsumer queueConsumer = new QueueingConsumer(consumer);
        consumer.basicConsume(queue, true, queueConsumer);
    
        QueueingConsumer.Delivery delivery = queueConsumer.nextDelivery(60 * 1000l); // one minute timeout
        assertEquals(delivery.getBody(), content);
    } finally {
        closeSafely(producer, 10*1000);
        closeSafely(consumer, 10*1000);
    }
}
 
Example 9
Source File: Consumer.java    From rabbitmq-tutorial with MIT License 5 votes vote down vote up
public static void main(String[] args) throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException, IOException, InterruptedException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setUri("amqp://guest:guest@localhost");
    factory.setConnectionTimeout(300000);
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare("my-queue", true, false, false, null);

    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume("my-queue", false, consumer);

    while (true) {
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();

        if (delivery != null) {
            try {
                String message = new String(delivery.getBody(), StandardCharsets.UTF_8);
                System.out.println("Message consumed: " + message);
                // Interact with IO
                channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
            } catch (Exception e) {
                channel.basicReject(delivery.getEnvelope().getDeliveryTag(), true);
            }
        }
    }

}
 
Example 10
Source File: Recv.java    From java-study with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
   // factory.setHost("localhost");
   //  factory.setHost("127.0.0.1");
    factory.setUri("amqp://guest:[email protected]:5672");//获取url
   // 打开连接和创建频道,与发送端一样  
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
 // 声明队列,主要为了防止消息接收者先运行此程序,队列还不存在时创建队列。  
    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
  // 创建队列消费者  
    QueueingConsumer consumer = new QueueingConsumer(channel);
    // 指定消费队列
    channel.basicConsume(QUEUE_NAME, true, consumer);
    while (true) {  //消费者程序运行开着 如果生产者新增了数据会自动获取
    	Thread.sleep(500);
    	 List aa=new ArrayList();
    	 // nextDelivery是一个阻塞方法(内部实现其实是阻塞队列的take方法)  
      QueueingConsumer.Delivery delivery = consumer.nextDelivery();
      String message = new String(delivery.getBody());
      aa.add(message);
      System.out.println("你好吗!"+" [x] Received '" + message + "'"+aa);
    }
   
  }
 
Example 11
Source File: TradeReader.java    From ThriftBook with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv)
    throws java.io.IOException,
           java.lang.InterruptedException,
           java.util.concurrent.TimeoutException,
           TException,
           TTransportException {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume(QUEUE_NAME, true, consumer);

    System.out.println("Waiting for trade reports...");
    while (true) {
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();
        byte[] data = delivery.getBody();
        TMemoryBuffer trans = new TMemoryBuffer(data.length);
        trans.write(data, 0, data.length);
        TCompactProtocol proto = new TCompactProtocol(trans);
        TradeReport tr = new TradeReport();
        tr.read(proto);
        System.out.println("[" + tr.seq_num + "] " + tr.symbol + 
                           " @ " + tr.price + " x " + tr.size);
    }
}
 
Example 12
Source File: Worker.java    From java-study with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    //factory.setHost("localhost");
  	factory.setUri("amqp://guest:[email protected]:5672");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    
    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);//queue的持久化需要在声明时指定durable=True
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
    //保证在接收端一个消息没有处理完时不会接收另一个消息
   channel.basicQos(1);
  //  channel.basicQos(0, 1, false); //这样RabbitMQ就会使得每个Consumer在同一个时间点最多处理一个Message。换句话说,在接收到该Consumer的ack前,他它不会将新的Message分发给它。
    
    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume(TASK_QUEUE_NAME, false, consumer);
    
    while (true) {
      QueueingConsumer.Delivery delivery = consumer.nextDelivery();
      String message = new String(delivery.getBody());
      
      System.out.println(" [x] Received '" + message + "'");
      doWork(message);
      System.out.println(" [x] Done");

      channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
    }         
  }
 
Example 13
Source File: Consumer.java    From code with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {


        //1 创建ConnectionFactory
        ConnectionFactory connectionFactory = new ConnectionFactory();
		connectionFactory.setHost(Constant.ip);
		connectionFactory.setPort(Constant.port);
        connectionFactory.setVirtualHost("/");

        //2 获取C	onnection
        Connection connection = connectionFactory.newConnection();

        //3 通过Connection创建一个新的Channel
        Channel channel = connection.createChannel();

        String exchangeName = "test_confirm_exchange";
        String routingKey = "confirm.#";
        String queueName = "test_confirm_queue";

        //4 声明交换机和队列 然后进行绑定设置, 最后制定路由Key
        channel.exchangeDeclare(exchangeName, "topic", true);
        channel.queueDeclare(queueName, true, false, false, null);
        channel.queueBind(queueName, exchangeName, routingKey);

        //5 创建消费者
        QueueingConsumer queueingConsumer = new QueueingConsumer(channel);
        channel.basicConsume(queueName, true, queueingConsumer);

        while (true) {
            Delivery delivery = queueingConsumer.nextDelivery();
            String msg = new String(delivery.getBody());

            System.err.println("消费端: " + msg);
        }


    }
 
Example 14
Source File: Consumer4TopicExchange.java    From code with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	
	
       ConnectionFactory connectionFactory = new ConnectionFactory() ;

       connectionFactory.setHost(Constant.ip);
       connectionFactory.setPort(Constant.port);
	connectionFactory.setVirtualHost("/");
	
       connectionFactory.setAutomaticRecoveryEnabled(true);
       connectionFactory.setNetworkRecoveryInterval(3000);
       Connection connection = connectionFactory.newConnection();
       
       Channel channel = connection.createChannel();  
	//4 声明
	String exchangeName = "test_topic_exchange";
	String exchangeType = "topic";
	String queueName = "test_topic_queue";
	String routingKey = "user.#";
	//String routingKey = "user.*";
	// 1 声明交换机 
	channel.exchangeDeclare(exchangeName, exchangeType, true, false, false, null);
	// 2 声明队列
	channel.queueDeclare(queueName, false, false, false, null);
	// 3 建立交换机和队列的绑定关系:
	channel.queueBind(queueName, exchangeName, routingKey);
	
       //durable 是否持久化消息
       QueueingConsumer consumer = new QueueingConsumer(channel);
       //参数:队列名称、是否自动ACK、Consumer
       channel.basicConsume(queueName, true, consumer);  
       //循环获取消息  
       while(true){  
           //获取消息,如果没有消息,这一步将会一直阻塞  
           Delivery delivery = consumer.nextDelivery();  
           String msg = new String(delivery.getBody());
           System.out.println("收到消息:" + msg);
       } 
}
 
Example 15
Source File: Consumer4DirectExchange.java    From code with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {


        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost(Constant.ip);
        connectionFactory.setPort(Constant.port);
        connectionFactory.setVirtualHost("/");

        connectionFactory.setAutomaticRecoveryEnabled(true);
        connectionFactory.setNetworkRecoveryInterval(3000);
        Connection connection = connectionFactory.newConnection();

        Channel channel = connection.createChannel();
        //4 声明
        String exchangeName = "test_direct_exchange";
        String exchangeType = "direct";
        String queueName = "test_direct_queue";
        String routingKey = "test.direct";

        //表示声明了一个交换机
        channel.exchangeDeclare(exchangeName, exchangeType, true, false, false, null);
        //表示声明了一个队列
        channel.queueDeclare(queueName, false, false, false, null);
        //建立一个绑定关系:
        channel.queueBind(queueName, exchangeName, routingKey);

        //durable 是否持久化消息
        QueueingConsumer consumer = new QueueingConsumer(channel);
        //参数:队列名称、是否自动ACK、Consumer
        channel.basicConsume(queueName, true, consumer);
        //循环获取消息  
        while (true) {
            //获取消息,如果没有消息,这一步将会一直阻塞  
            Delivery delivery = consumer.nextDelivery();
            String msg = new String(delivery.getBody());
            System.out.println("收到消息:" + msg);
        }
    }
 
Example 16
Source File: Consumer4FanoutExchange.java    From code with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	
       ConnectionFactory connectionFactory = new ConnectionFactory() ;
       connectionFactory.setHost(Constant.ip);
       connectionFactory.setPort(Constant.port);
	connectionFactory.setVirtualHost("/");
	
       connectionFactory.setAutomaticRecoveryEnabled(true);
       connectionFactory.setNetworkRecoveryInterval(3000);
       Connection connection = connectionFactory.newConnection();
       
       Channel channel = connection.createChannel();  
	//4 声明
	String exchangeName = "test_fanout_exchange";
	String exchangeType = "fanout";
	String queueName = "test_fanout_queue";
	String routingKey = "";	//不设置路由键
	channel.exchangeDeclare(exchangeName, exchangeType, true, false, false, null);
	channel.queueDeclare(queueName, false, false, false, null);
	channel.queueBind(queueName, exchangeName, routingKey);
	
       //durable 是否持久化消息
       QueueingConsumer consumer = new QueueingConsumer(channel);
       //参数:队列名称、是否自动ACK、Consumer
       channel.basicConsume(queueName, true, consumer); 
       //循环获取消息  
       while(true){  
           //获取消息,如果没有消息,这一步将会一直阻塞  
           Delivery delivery = consumer.nextDelivery();  
           String msg = new String(delivery.getBody());
           System.out.println("收到消息:" + msg);
       } 
}
 
Example 17
Source File: Consumer.java    From code with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        //1 创建一个ConnectionFactory, 并进行配置
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost(Constant.ip);
        connectionFactory.setPort(Constant.port);
        connectionFactory.setVirtualHost("/");

        //2 通过连接工厂创建连接
        Connection connection = connectionFactory.newConnection();

        //3 通过connection创建一个Channel
        Channel channel = connection.createChannel();

        //4 声明(创建)一个队列
        String queueName = "test001";
        channel.queueDeclare(queueName, true, false, false, null);

        //5 创建消费者
        QueueingConsumer queueingConsumer = new QueueingConsumer(channel);

        //6 设置Channel
        channel.basicConsume(queueName, true, queueingConsumer);

        while (true) {
            //7 获取消息
            Delivery delivery = queueingConsumer.nextDelivery();
            String msg = new String(delivery.getBody());
            System.err.println("消费端: " + msg);
            Map<String, Object> headers = delivery.getProperties().getHeaders();
            System.err.println("headers get my1 value: " + headers.get("my1") + "\tmy1 value:" + headers.get("my2"));

            //Envelope envelope = delivery.getEnvelope();
        }

    }
 
Example 18
Source File: Consumer.java    From code with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
    //1、创建一个ConnectionFactory, 并进行配置
    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setHost(Constant.ip);
    connectionFactory.setPort(Constant.port);
    connectionFactory.setVirtualHost("/");

    //2、通过连接工厂创建连接
    Connection connection = connectionFactory.newConnection();

    //3、通过connection创建一个Channel
    Channel channel = connection.createChannel();

    //4、声明(创建)一个队列
    String queueName = "test001";
    channel.queueDeclare(queueName, true, false, false, null);

    //5、创建消费者
    QueueingConsumer queueingConsumer = new QueueingConsumer(channel);

    //6、设置channel
    channel.basicConsume(queueName, true, queueingConsumer);

    while (true) {
        //7、 获取消息
        QueueingConsumer.Delivery delivery = queueingConsumer.nextDelivery();
        String msg = new String(delivery.getBody());
        System.err.println("消费端: " + msg);
        //Envelope envelope = delivery.getEnvelope();
    }

}
 
Example 19
Source File: AMQPProducer.java    From reactive with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public void execute(String mode) throws Exception {
	channel = AMQPCommon.connect();
	QueueingConsumer consumer = new QueueingConsumer(channel);
	channel.basicConsume("trade.response.q", true, consumer);

	//cleanup any left over messages before continuing...
	while (true) {
		if (consumer.nextDelivery(1000) == null) break;
		System.out.print(".");
	}
	
	if (mode.equalsIgnoreCase("stddev")) {
		timeout = 20;
		durations.add(100l);
		durations.add(200l);
		durations.add(300l);
		durations.add(400l);
		durations.add(500l);
		durations.add(600l);
		durations.add(700l);
		durations.add(800l);
		durations.add(900l);
		durations.add(1000l);
	}
	
	while (true) {
		System.out.println("");
		long start = System.currentTimeMillis();
		long shares = ((long) ((new Random().nextDouble() * 4000) + 1));
		String text = "BUY,AAPL," + shares;
		byte[] message = text.getBytes();
		System.out.println("sending trade order: " + text);
		channel.basicPublish("", "trade.request.q", null, message);
		consumer.nextDelivery();
		tradeCount++;
		long end = System.currentTimeMillis();
		long duration = end - start;
		if (duration > (current*2)) {
			System.out.println("request timed out...");
		} else {
			System.out.println("trade confirmation received in " + duration + "ms");

			if (mode.equalsIgnoreCase("simple")) {
				adjustSimple(duration);
			} else if (mode.equalsIgnoreCase("bracket")) {
				adjustBracket(duration, false);
			} else if (mode.equalsIgnoreCase("stddev")) {
				adjustBracket(duration, true);
			}
		}
		
		Thread.sleep(1000);
	}
}
 
Example 20
Source File: BatchWriterService.java    From neo4j-mazerunner with Apache License 2.0 4 votes vote down vote up
@Override
protected void runOneIteration() throws Exception {
    logger.info("Connecting to RabbitMQ processor queue...");

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(ConfigurationLoader.getInstance().getRabbitmqNodename());
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    channel.basicQos(1);

    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume(TASK_QUEUE_NAME, false, consumer);

    while (true) {
        QueueingConsumer.Delivery delivery = null;
        try {
            delivery = consumer.nextDelivery(40000L);

            if(delivery != null) {
                String message = new String(delivery.getBody());

                System.out.println(" [x] Received processor message '" + message + "'");

                // Deserialize the processor message
                Gson gson = new Gson();
                ProcessorMessage processorMessage = gson.fromJson(message, ProcessorMessage.class);

                // Open the node property update list file from HDFS
                BufferedReader bufferedReader = FileUtil.readGraphAdjacencyList(processorMessage);

                switch (processorMessage.getMode()) {
                    case Partitioned:
                        PartitionedAnalysis.updatePartition(processorMessage, bufferedReader, graphDb);
                        break;
                    case Unpartitioned:
                        if (Objects.equals(processorMessage.getAnalysis(), JobRequestType.COLLABORATIVE_FILTERING.toString().toLowerCase())) {
                            Writer.asyncImportCollaborativeFiltering(bufferedReader, graphDb);
                        } else {
                            // Stream the the updates as parallel transactions to Neo4j
                            Writer.asyncUpdate(processorMessage, bufferedReader, graphDb);
                        }
                        break;
                }

                // Close the stream
                bufferedReader.close();

                System.out.println(" [x] Done");

                channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("Waiting...");

            // Hold on error cycle to prevent high throughput writes to console log
            Thread.sleep(5000);
            System.out.println("Recovered...");

            if(delivery != null)
                channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
        }
    }
}