ActiveMQ的并发在Apache的骆驼航线失败 [英] Activemq concurrency fail in Apache camel route

查看:413
本文介绍了ActiveMQ的并发在Apache的骆驼航线失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图在同一时刻发送多个请求骆驼ActiveMQ的路线,一个请求服务,其他请求不提供服务,并发送回原样。该JMS消息太下方发送像以前那样设定JMScorrelationId

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());

下面是我的ActiveMQ路线

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");

多个(测试2请求)发送到上述航线同时不提供服务除了一个请求。该servicemix.log显示所有收到的请求。但只有一个服务程序。

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.

下面是code是什么发送请求部署到JBoss 6.1的Web应用程序的一部分。

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;
    }

有一些或其他参数IM失踪?请建议。

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

推荐答案

骆驼会自动发回的回应,如果JMS消息具有JMSReplyTo头,让你的路线应该只是

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");

目前的路线(例如,主叫testBean这个后),则消息正文的内容被用作应答消息,发送回名为JMSReplyTo头定义的队列的末尾。

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.

这篇关于ActiveMQ的并发在Apache的骆驼航线失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆