Guest User

Untitled

a guest
Jan 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. protected LinkedBlockingQueue<Message> messages = new LinkedBlockingQueue<>();
  2.  
  3. public void receiveMessages() {
  4. try {
  5. // channel.basicQos(pollCount);
  6. Message message = new Message();
  7. Consumer consumer = new DefaultConsumer(channel) {
  8. @Override
  9. public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
  10. throws IOException {
  11. long deliveryTag = envelope.getDeliveryTag();
  12. String response = new String(body, "UTF-8");
  13. if (response != null) {
  14. message.setId(NUID.nextGlobal());
  15. message.setPayload(response);
  16. message.setDeliveryTag(deliveryTag);
  17. messages.add(message);
  18. logger.info("Message received: ", message.getPayload());
  19. }
  20. }
  21. };
  22. logger.debug("**********Channel status: " + channel.isOpen());
  23. channel.basicConsume(queueName, false, consumer);
  24. } catch (Exception e) {
  25. logger.error("Exception while getting messages from Rabbit ", e);
  26.  
  27. }
  28. }
Add Comment
Please, Sign In to add comment