Search in sources :

Example 1 with TopicRequestor

use of javax.jms.TopicRequestor in project activemq-artemis by apache.

the class TopicBridgeSpringTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    context = createApplicationContext();
    ActiveMQConnectionFactory fac = (ActiveMQConnectionFactory) context.getBean("localFactory");
    localConnection = fac.createTopicConnection();
    localConnection.start();
    requestServerSession = localConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic theTopic = requestServerSession.createTopic(getClass().getName());
    requestServerConsumer = requestServerSession.createConsumer(theTopic);
    requestServerConsumer.setMessageListener(this);
    requestServerProducer = requestServerSession.createProducer(null);
    fac = (ActiveMQConnectionFactory) context.getBean("remoteFactory");
    remoteConnection = fac.createTopicConnection();
    remoteConnection.start();
    TopicSession session = remoteConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    requestor = new TopicRequestor(session, theTopic);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) TopicRequestor(javax.jms.TopicRequestor) TopicSession(javax.jms.TopicSession) Topic(javax.jms.Topic)

Example 2 with TopicRequestor

use of javax.jms.TopicRequestor in project activemq-artemis by apache.

the class SimpleNetworkTest method testRequestReply.

@Test(timeout = 60 * 1000)
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) {
            try {
                TextMessage textMsg = (TextMessage) msg;
                String payload = "REPLY: " + textMsg.getText();
                Destination replyTo;
                replyTo = msg.getJMSReplyTo();
                textMsg.clearBody();
                textMsg.setText(payload);
                remoteProducer.send(replyTo, textMsg);
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    });
    TopicRequestor requestor = new TopicRequestor((TopicSession) localSession, included);
    // allow for consumer infos to perculate around
    Thread.sleep(5000);
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        TextMessage msg = localSession.createTextMessage("test msg: " + i);
        TextMessage result = (TextMessage) requestor.request(msg);
        assertNotNull(result);
        LOG.info(result.getText());
    }
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) TopicRequestor(javax.jms.TopicRequestor) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 3 with TopicRequestor

use of javax.jms.TopicRequestor in project activemq by apache.

the class SimpleNetworkTest method testRequestReply.

@Test(timeout = 60 * 1000)
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) {
            try {
                TextMessage textMsg = (TextMessage) msg;
                String payload = "REPLY: " + textMsg.getText();
                Destination replyTo;
                replyTo = msg.getJMSReplyTo();
                textMsg.clearBody();
                textMsg.setText(payload);
                remoteProducer.send(replyTo, textMsg);
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    });
    TopicRequestor requestor = new TopicRequestor((TopicSession) localSession, included);
    // allow for consumer infos to perculate arround
    Thread.sleep(5000);
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        TextMessage msg = localSession.createTextMessage("test msg: " + i);
        TextMessage result = (TextMessage) requestor.request(msg);
        assertNotNull(result);
        LOG.info(result.getText());
    }
    assertNetworkBridgeStatistics(MESSAGE_COUNT, MESSAGE_COUNT);
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) TopicRequestor(javax.jms.TopicRequestor) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 4 with TopicRequestor

use of javax.jms.TopicRequestor in project activemq by apache.

the class TopicBridgeSpringTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    context = createApplicationContext();
    ActiveMQConnectionFactory fac = (ActiveMQConnectionFactory) context.getBean("localFactory");
    localConnection = fac.createTopicConnection();
    localConnection.start();
    requestServerSession = localConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic theTopic = requestServerSession.createTopic(getClass().getName());
    requestServerConsumer = requestServerSession.createConsumer(theTopic);
    requestServerConsumer.setMessageListener(this);
    requestServerProducer = requestServerSession.createProducer(null);
    fac = (ActiveMQConnectionFactory) context.getBean("remoteFactory");
    remoteConnection = fac.createTopicConnection();
    remoteConnection.start();
    TopicSession session = remoteConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    requestor = new TopicRequestor(session, theTopic);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) TopicRequestor(javax.jms.TopicRequestor) TopicSession(javax.jms.TopicSession) Topic(javax.jms.Topic)

Aggregations

TopicRequestor (javax.jms.TopicRequestor)4 Destination (javax.jms.Destination)2 JMSException (javax.jms.JMSException)2 Message (javax.jms.Message)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageListener (javax.jms.MessageListener)2 MessageProducer (javax.jms.MessageProducer)2 TextMessage (javax.jms.TextMessage)2 Topic (javax.jms.Topic)2 TopicSession (javax.jms.TopicSession)2 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)2 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)2 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)2 Test (org.junit.Test)2