Search in sources :

Example 1 with DestinationDoesNotExistException

use of org.apache.activemq.DestinationDoesNotExistException in project activemq-artemis by apache.

the class NetworkFailoverTest method testRequestReply.

public void testRequestReply() throws Exception {
    final MessageProducer remoteProducer = remoteSession.createProducer(null);
    MessageConsumer remoteConsumer = remoteSession.createConsumer(included);
    remoteConsumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message msg) {
            final TextMessage textMsg = (TextMessage) msg;
            try {
                String payload = "REPLY: " + textMsg.getText() + ", " + textMsg.getJMSMessageID();
                Destination replyTo;
                replyTo = msg.getJMSReplyTo();
                textMsg.clearBody();
                textMsg.setText(payload);
                LOG.info("*** Sending response: {}", textMsg.getText());
                remoteProducer.send(replyTo, textMsg);
                LOG.info("replied with: " + textMsg.getJMSMessageID());
            } catch (DestinationDoesNotExistException expected) {
                // been removed but not yet recreated
                replyToNonExistDest.incrementAndGet();
                try {
                    LOG.info("NED: " + textMsg.getJMSMessageID());
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            } catch (Exception e) {
                LOG.warn("*** Responder listener caught exception: ", e);
                e.printStackTrace();
            }
        }
    });
    Queue tempQueue = localSession.createTemporaryQueue();
    MessageProducer requestProducer = localSession.createProducer(included);
    requestProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    MessageConsumer requestConsumer = localSession.createConsumer(tempQueue);
    // track remote dlq for forward failures
    MessageConsumer dlqconsumer = remoteSession.createConsumer(new ActiveMQQueue(SharedDeadLetterStrategy.DEFAULT_DEAD_LETTER_QUEUE_NAME));
    dlqconsumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            try {
                LOG.info("dlq " + message.getJMSMessageID());
            } catch (JMSException e) {
                e.printStackTrace();
            }
            remoteDLQCount.incrementAndGet();
        }
    });
    // allow for consumer infos to perculate around
    Thread.sleep(2000);
    long done = System.currentTimeMillis() + (MESSAGE_COUNT * 6000);
    int i = 0;
    while (MESSAGE_COUNT > roundTripComplete.get() + remoteDLQCount.get() + replyToNonExistDest.get() && done > System.currentTimeMillis()) {
        if (i < MESSAGE_COUNT) {
            String payload = "test msg " + i;
            i++;
            TextMessage msg = localSession.createTextMessage(payload);
            msg.setJMSReplyTo(tempQueue);
            requestProducer.send(msg);
            LOG.info("Sent: " + msg.getJMSMessageID() + ", Failing over");
            ((FailoverTransport) ((TransportFilter) ((TransportFilter) ((ActiveMQConnection) localConnection).getTransport()).getNext()).getNext()).handleTransportFailure(new IOException("Forcing failover from test"));
        }
        TextMessage result = (TextMessage) requestConsumer.receive(5000);
        if (result != null) {
            LOG.info("Got reply: " + result.getJMSMessageID() + ", " + result.getText());
            roundTripComplete.incrementAndGet();
        }
    }
    LOG.info("complete: " + roundTripComplete.get() + ", remoteDLQCount: " + remoteDLQCount.get() + ", replyToNonExistDest: " + replyToNonExistDest.get());
    assertEquals("complete:" + roundTripComplete.get() + ", remoteDLQCount: " + remoteDLQCount.get() + ", replyToNonExistDest: " + replyToNonExistDest.get(), MESSAGE_COUNT, roundTripComplete.get() + remoteDLQCount.get() + replyToNonExistDest.get());
}
Also used : DestinationDoesNotExistException(org.apache.activemq.DestinationDoesNotExistException) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException) FailoverTransport(org.apache.activemq.transport.failover.FailoverTransport) IOException(java.io.IOException) TransportFilter(org.apache.activemq.transport.TransportFilter) DestinationDoesNotExistException(org.apache.activemq.DestinationDoesNotExistException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage)

Aggregations

IOException (java.io.IOException)1 Destination (javax.jms.Destination)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageListener (javax.jms.MessageListener)1 MessageProducer (javax.jms.MessageProducer)1 Queue (javax.jms.Queue)1 TextMessage (javax.jms.TextMessage)1 DestinationDoesNotExistException (org.apache.activemq.DestinationDoesNotExistException)1 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)1 TransportFilter (org.apache.activemq.transport.TransportFilter)1 FailoverTransport (org.apache.activemq.transport.failover.FailoverTransport)1