Временная очередь JMS - ответы, не возвращаемые клиенту - PullRequest
0 голосов
/ 18 мая 2018

Я пытаюсь перейти от Weblogic к JBoss, и поэтому я пытаюсь реализовать то, что смог реализовать в Weblogic на JBoss.

Одной из таких вещей является наша система уведомлений.где клиент отправляет запрос в 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 голосов
/ 17 июля 2019

Проблема заключалась в настройке целевой очереди, которая является удаленной очередью: клиент и сервер работают на разных 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

...