Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ExecutorService executor = Executors.newFixedThreadPool(30);
- Connection connection = factory.newConnection(executor);
- for(int i=0;i<=30;i++) {
- ConsumerApp consumer = new ConsumerApp(i,connection.createChanell());
- consumer.listen() }
- listen() {
- try {
- channel.queueDeclare("test-queue-name", false, false, false, null);
- }
- catch {
- System.out.println("Exception on creating Queue")
- }
- Consumer consumer = new DefaultConsumer(this.channel) {
- @Override
- public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
- byte[] body) throws IOException {
- String message = new String(body, "UTF-8");
- System.out.println(" [x] Received Message in consumer '"+consumerId+" "+ message + "'");
- }
- };
- //Now starting the consumer
- try {
- channel.basicConsume(QUEUE_NAME, true, consumer);
- }
- catch (ShutdownSignalException | IOException ex) {
- ex.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment