Activemq concurrency fail in Apache camel route

醉酒当歌 提交于 2019-12-13 03:34:21

问题


Trying to send multiple requests at same instant to camel activemq route, one request is serviced and the other request is not serviced and sent back as it is. The Jms messages are set with JMScorrelationId too before sending like below

textMessage.setJMSCorrelationID(UUID.randomUUID().toString());

below is my activemq route

from("activemq:queue:TEST_QUEUE?disableReplyTo=true")
                .setExchangePattern(ExchangePattern.InOut)
                .process(new Processor() {
                    public void process(Exchange e) throws Exception {
                        log.info("Request : "
                                + MessageHelper.extractBodyAsString(e.getIn()));
                        /*Processing Logic*/
                    }
                })
                .beanRef("testBean","postDetails")
                .inOnly("activemq:queue:TEST_QUEUE");

Multiple (Test for 2 requests) requests sent to the above route concurrently not serviced except one. The servicemix.log shows all recieved requests. But only one is serviced.

Below is the code what is sending request deployed in jboss 6.1 as part of web application.

public Message receive(String message, String queueName) {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
                "tcp://localhost:61616");
        String userName = "smx";
        String password = "smx";
        Connection connection;
        Message response =null;
        try {
            connection = connectionFactory.createConnection(userName, password);
            connection.start();
            ((ActiveMQConnectionFactory) connectionFactory)
                    .setDispatchAsync(false);
            Session session = connection.createSession(false,
                    Session.AUTO_ACKNOWLEDGE);
            Queue destination = session.createQueue(queueName);
            MessageProducer producer = session.createProducer(destination);
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            TextMessage textMessage = session.createTextMessage(message);
            Queue tempQueue = session.createQueue(queueName);
            textMessage.setJMSReplyTo(tempQueue);
            producer.send(textMessage);
            MessageConsumer consumer = session.createConsumer(tempQueue);
            response = consumer.receive();
            response.acknowledge();

            session.close();
            connection.close();
        } catch (JMSException e) {
            e.printStackTrace();
        }
        return response;
    }

Is there some or the other parameter im missing?? please suggest.


回答1:


Camel will auto send back a reply if the JMS message has a JMSReplyTo header, so your route should just be

from("activemq:queue:TEST_QUEUE")
                .process(new Processor() {
                    public void process(Exchange e) throws Exception {
                        log.info("Request : "
                                + MessageHelper.extractBodyAsString(e.getIn()));
                        /*Processing Logic*/
                    }
                })
                .beanRef("testBean","postDetails");

At the end of the route (eg after calling testBean) then the content of the message body is used as the reply message, that are sent back to the queue named defined in the JMSReplyTo header.



来源:https://stackoverflow.com/questions/33887676/activemq-concurrency-fail-in-apache-camel-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!