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

JMS Temporary Queue - Replies not returning back to client

我正在尝试从 Weblogic 转移到 JBoss,因此我正在尝试在 JBoss.[=13= 上实现我能够在 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
        }
    }
}

问题与作为远程队列的目标队列的配置有关:客户端和服务器都 运行 在不同的 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