JMS临时队列 - 回复不返回客户端

时间:2018-05-18 15:48:21

标签: jms jboss-eap-7

我试图从Weblogic转移到JBoss,因此我试图实现我能够在JBoss上的Weblogic上实现的东西。

其中一个是我们的通知系统,客户端向MDB发送请求,MDB将回复发送回客户端。

这在Weblogic中是轻而易举的,但在Jboss上,似乎没有任何效果。我一直收到这个错误:

javax.jms.InvalidDestinationException: Not an ActiveMQ Artemis Destination:ActiveMQTemporaryQueue[da00b1a2-114d-4be9-930d-926fc20c2fce]

我需要在Jboss上配置一些东西吗?

修改

我意识到我可能没有很好地说出这个问题。

这是怎么回事:我有一个客户端和一个服务器MDB(消息驱动的bean)。客户端将消息发送到队列并等待来自服务器的响应。服务器从队列中选择消息并向客户端发送响应,客户端将其选中并显示。

在Jboss上,来自客户端的消息顺利进行,服务器将其选中,但是一旦服务器MDB尝试向客户端发送响应,就会抛出该错误。

我的客户代码(摘录):

int TIME_OUT = 60000;

            //prepare factory
            Properties prop = new Properties();
            prop.setProperty("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
            prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
            prop.setProperty("java.naming.provider.url", "http-remoting://remotehost:8080");
            prop.setProperty("java.naming.security.principal", "guest-user")
            prop.setProperty("java.naming.security.credentials", "Password@1")

            String queueConnectionFactory = "jms/RemoteConnectionFactory";

            Context context = new InitialContext(prop);
            QueueConnectionFactory qconFactory = (QueueConnectionFactory) context.lookup(queueConnectionFactory);

            //prepare queue and sessions
            QueueConnection qcon = qconFactory.createQueueConnection(prop.getProperty("java.naming.security.principal"), prop.getProperty("java.naming.security.credentials"));
            QueueSession qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            Queue queue = (Queue) context.lookup("jms/TestQueue2");

            //create message
            NotificationWrapper wrapper = //object initialised with something
            ObjectMessage om = qsession.createObjectMessage(wrapper);//NotificationWrapper wrapper

            //create producer
            MessageProducer producer = qsession.createProducer(queue);

            //create temporary queue
            TemporaryQueue tempqueue = qsession.createTemporaryQueue();
            om.setJMSReplyTo(tempqueue);

            //start connection
            qcon.start();

            //send message and wait for response
            producer.send(om);
            MessageConsumer consumer = qsession.createConsumer(tempqueue);
            Message callback = consumer.receive(TIME_OUT);

            //print message from server
            if (callback != null) {
                System.out.println("Response received from server. Print here...");
                //message from server
            } else {
                System.out.println("No Response received from server. Problems!!!");
            }

            //close all connections
            if (consumer != null) {
                consumer.close();
            }
            if (producer != null) {
                producer.close();
            }
            if (qsession != null) {
                qsession.close();
            }
            if (qcon != null) {
                qcon.close();
            }

我的服务器代码(摘录):

@MessageDriven(mappedName = "TestQueue2", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/TestQueue2"),
    @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "10")
})
public class ServerSide implements MessageListener {
    private static final QueueConfigProperties queueConfigProp = QueueConfigProperties.getInstance();
    private Context context;
    private QueueConnectionFactory qconFactory;
    private QueueConnection qcon;
    private QueueSession qsession;
    private MessageProducer producer;

    public ServerSide() {
        try {
            initialiseQueueFactory("jms/RemoteConnectionFactory");
            //initialiseQueueFactory("jms/GreenpoleConnectionFactory");
            prepareResponseQueue();
            Properties prop = new Properties();
            prop.setProperty("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
            prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
            prop.setProperty("java.naming.provider.url", "http-remoting://remotehost:8080");
            prop.setProperty("java.naming.security.principal", "guest-user")
            prop.setProperty("java.naming.security.credentials", "Password@1")

            String queueConnectionFactory = "jms/RemoteConnectionFactory";

            Context context = new InitialContext(prop);
            QueueConnectionFactory qconFactory = (QueueConnectionFactory) context.lookup(queueConnectionFactory);

            qcon = qconFactory.createQueueConnection(queueConfigProp.getProperty("java.naming.security.principal"), queueConfigProp.getProperty("java.naming.security.credentials"));
            qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        } catch (NamingException | ConfigNotFoundException | IOException | JMSException ex) {
            //error log
        }
    }

    @Override
    public void onMessage(Message message) {
        try {
            if (((ObjectMessage) message).getObject() instanceof NotificationWrapper) {
                //send response
                if (message.getJMSReplyTo() != null) {
                    logger.info("sending response");
                    respondToSenderPositive(message);

                    Response resp = new Response();
                    resp.setRetn(0);
                    resp.setDesc("Notification submitted to queue.");

                    producer = qsession.createProducer(message.getJMSReplyTo());
                    producer.send(qsession.createObjectMessage(resp));

                    producer.send(msg_to_send);
                }
            } else {
                //some message printed here
            }
        } catch (JMSException ex) {
            //error logs
        } catch (Exception ex) {
            //error logs
        }
    }
}

1 个答案:

答案 0 :(得分:0)

问题与目标队列(即远程队列)的配置有关:客户端和服务器都在不同的JVM上运行。 Jboss上的远程队列的名称与Weblogic上的不同。

远程队列的名称应类似于以下内容:java:jboss/exported/jms/TestQueue2

有关队列的更详细说明,请参见JBoss文档:https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html-single/configuring_messaging/index