Search in sources :

Example 61 with Destination

use of javax.jms.Destination in project rocketmq-externals by apache.

the class JmsConsumerIT method testReferenceCount.

@Test
public void testReferenceCount() throws Exception {
    JmsBaseConnectionFactory connectionFactory = new JmsBaseConnectionFactory(new URI("rocketmq://xxx?consumerId=" + consumerId + "&nameServer=" + nameServer));
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    connection.start();
    try {
        Destination destination = session.createTopic(topic + ":" + messageType);
        MessageConsumer consumer = session.createConsumer(destination);
        consumer.setMessageListener(listener);
        RMQPushConsumerExt rmqPushConsumerExt = getRMQPushConsumerExt(consumerId);
        Assert.assertNotNull(rmqPushConsumerExt);
        Assert.assertEquals(1, rmqPushConsumerExt.getReferenceCount());
        MessageConsumer consumer2 = session.createConsumer(destination);
        Assert.assertEquals(2, rmqPushConsumerExt.getReferenceCount());
        MessageConsumer consumer3 = session.createConsumer(session.createTopic(topic + ":" + messageType));
        Assert.assertEquals(3, rmqPushConsumerExt.getReferenceCount());
        session.close();
        Assert.assertEquals(0, rmqPushConsumerExt.getReferenceCount());
        Assert.assertEquals(false, rmqPushConsumerExt.isStarted());
        Assert.assertNull(getRMQPushConsumerExt(consumerId));
        Thread.sleep(5000);
    } finally {
        connection.close();
    }
}
Also used : Destination(javax.jms.Destination) JmsBaseMessageConsumer(org.apache.rocketmq.jms.domain.JmsBaseMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) JmsTestUtil.getRMQPushConsumerExt(org.apache.rocketmq.jms.JmsTestUtil.getRMQPushConsumerExt) RMQPushConsumerExt(org.apache.rocketmq.jms.domain.RMQPushConsumerExt) JmsBaseConnectionFactory(org.apache.rocketmq.jms.domain.JmsBaseConnectionFactory) Connection(javax.jms.Connection) URI(java.net.URI) Session(javax.jms.Session) Test(org.junit.Test)

Example 62 with Destination

use of javax.jms.Destination in project rocketmq-externals by apache.

the class SimpleExMessageListenerContainer method createListenerConsumer.

/**
 * Create a MessageConsumer for the given JMS Session, registering a
 * MessageListener for the specified listener.
 *
 * @param session
 *         the JMS Session to work on
 *
 * @return the MessageConsumer
 *
 * @throws JMSException
 *         if thrown by JMS methods
 * @see #executeListener
 */
protected MessageConsumer createListenerConsumer(final Session session) throws JMSException {
    Destination destination = getDestination();
    if (destination == null) {
        destination = resolveDestinationName(session, getDestinationName());
    }
    MessageConsumer consumer = createConsumer(session, destination);
    consumer.setMessageListener((MessageListener) super.getMessageListener());
    return consumer;
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer)

Example 63 with Destination

use of javax.jms.Destination in project wso2-axis2-transports by wso2.

the class JMSSenderTestCase method testIsWaitForResponseOrReplyDestinationWhenOneIsTrue.

public void testIsWaitForResponseOrReplyDestinationWhenOneIsTrue() throws Exception {
    JMSSender jmsSender = new JMSSender();
    boolean result1 = jmsSender.isWaitForResponseOrReplyDestination(true, null);
    Assert.assertTrue(assertErrorMessageForTrue, result1);
    Destination destination = Mockito.mock(Destination.class);
    boolean result2 = jmsSender.isWaitForResponseOrReplyDestination(false, destination);
    Assert.assertTrue(assertErrorMessageForTrue, result2);
}
Also used : Destination(javax.jms.Destination)

Example 64 with Destination

use of javax.jms.Destination in project wso2-axis2-transports by wso2.

the class JMSSenderTestCase method testIsWaitForResponseOrReplyDestinationBothTrue.

public void testIsWaitForResponseOrReplyDestinationBothTrue() throws Exception {
    JMSSender jmsSender = new JMSSender();
    Destination destination = Mockito.mock(Destination.class);
    boolean result = jmsSender.isWaitForResponseOrReplyDestination(true, destination);
    Assert.assertTrue(assertErrorMessageForTrue, result);
}
Also used : Destination(javax.jms.Destination)

Example 65 with Destination

use of javax.jms.Destination in project wso2-axis2-transports by wso2.

the class MockEchoEndpoint method setUp.

@Setup
@SuppressWarnings("unused")
private void setUp(JMSTestEnvironment env, JMSRequestResponseChannel channel) throws Exception {
    Destination destination = channel.getDestination();
    Destination replyDestination = channel.getReplyDestination();
    connection = env.getConnectionFactory().createConnection();
    connection.setExceptionListener(this);
    connection.start();
    replyConnection = env.getConnectionFactory().createConnection();
    replyConnection.setExceptionListener(this);
    final Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final MessageProducer producer = replySession.createProducer(replyDestination);
    MessageConsumer consumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(destination);
    consumer.setMessageListener(new MessageListener() {

        public void onMessage(Message message) {
            try {
                log.info("Message received: ID = " + message.getJMSMessageID());
                Message reply;
                if (message instanceof BytesMessage) {
                    reply = replySession.createBytesMessage();
                    IOUtils.copy(new BytesMessageInputStream((BytesMessage) message), new BytesMessageOutputStream((BytesMessage) reply));
                } else if (message instanceof TextMessage) {
                    reply = replySession.createTextMessage();
                    ((TextMessage) reply).setText(((TextMessage) message).getText());
                } else {
                    // TODO
                    throw new UnsupportedOperationException("Unsupported message type");
                }
                reply.setJMSCorrelationID(message.getJMSMessageID());
                reply.setStringProperty(BaseConstants.CONTENT_TYPE, message.getStringProperty(BaseConstants.CONTENT_TYPE));
                producer.send(reply);
                log.info("Message sent: ID = " + reply.getJMSMessageID());
            } catch (Throwable ex) {
                fireEndpointError(ex);
            }
        }
    });
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) MessageListener(javax.jms.MessageListener) BytesMessage(javax.jms.BytesMessage) BytesMessageOutputStream(org.apache.axis2.transport.jms.iowrappers.BytesMessageOutputStream) MessageProducer(javax.jms.MessageProducer) BytesMessageInputStream(org.apache.axis2.transport.jms.iowrappers.BytesMessageInputStream) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Setup(org.apache.axis2.transport.testkit.tests.Setup)

Aggregations

Destination (javax.jms.Destination)178 Test (org.junit.Test)51 TextMessage (javax.jms.TextMessage)47 Session (javax.jms.Session)46 JMSException (javax.jms.JMSException)45 Connection (javax.jms.Connection)32 MessageProducer (javax.jms.MessageProducer)31 Message (javax.jms.Message)30 ConnectionFactory (javax.jms.ConnectionFactory)24 MessageConsumer (javax.jms.MessageConsumer)24 JMSContext (javax.jms.JMSContext)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 ObjectMessage (javax.jms.ObjectMessage)12 StubTextMessage (org.springframework.jms.StubTextMessage)11 InitialContext (javax.naming.InitialContext)10 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)10 Queue (javax.jms.Queue)8 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)8 MapMessage (javax.jms.MapMessage)7 HashMap (java.util.HashMap)6