Guest User

Untitled

a guest
Jun 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. ExecutorService executor = Executors.newFixedThreadPool(30);
  2. Connection connection = factory.newConnection(executor);
  3.  
  4. for(int i=0;i<=30;i++) {
  5. ConsumerApp consumer = new ConsumerApp(i,connection.createChanell());
  6. consumer.listen() }
  7.  
  8. listen() {
  9. try {
  10. channel.queueDeclare("test-queue-name", false, false, false, null);
  11. }
  12. catch {
  13. System.out.println("Exception on creating Queue")
  14. }
  15. Consumer consumer = new DefaultConsumer(this.channel) {
  16. @Override
  17. public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
  18. byte[] body) throws IOException {
  19. String message = new String(body, "UTF-8");
  20. System.out.println(" [x] Received Message in consumer '"+consumerId+" "+ message + "'");
  21. }
  22. };
  23. //Now starting the consumer
  24. try {
  25. channel.basicConsume(QUEUE_NAME, true, consumer);
  26. }
  27. catch (ShutdownSignalException | IOException ex) {
  28. ex.printStackTrace();
  29. }
  30. }
Add Comment
Please, Sign In to add comment