use of javax.jms.TopicPublisher in project rabbitmq-jms-client by rabbitmq.
the class SSLSimpleTopicMessageIT method testSendAndReceiveTextMessage.
@Test
public void testSendAndReceiveTextMessage() throws Exception {
final String MESSAGE2 = "Hello " + SSLSimpleTopicMessageIT.class.getName();
topicConn.start();
TopicSession topicSession = topicConn.createTopicSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Topic topic = topicSession.createTopic(TOPIC_NAME);
TopicPublisher sender = topicSession.createPublisher(topic);
TopicSubscriber receiver1 = topicSession.createSubscriber(topic);
TopicSubscriber receiver2 = topicSession.createSubscriber(topic);
sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = topicSession.createTextMessage(MESSAGE2);
sender.send(message);
assertEquals(MESSAGE2, ((TextMessage) receiver1.receive()).getText());
assertEquals(MESSAGE2, ((TextMessage) receiver2.receive()).getText());
}
use of javax.jms.TopicPublisher in project rabbitmq-jms-client by rabbitmq.
the class SelectorAppliedToTopicNotQueueIT method sendAndReceive.
private void sendAndReceive(TopicSession topicSession, Topic topic, MessageConsumer receiver) throws JMSException {
TopicPublisher sender = topicSession.createPublisher(topic);
sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = topicSession.createTextMessage(MESSAGE1);
message.setBooleanProperty("boolProp", true);
sender.send(message);
RMQTextMessage tmsg = (RMQTextMessage) receiver.receive();
String t = tmsg.getText();
assertEquals(MESSAGE1, t);
}
use of javax.jms.TopicPublisher in project rabbitmq-jms-client by rabbitmq.
the class SimpleDurableTopicMessageIT method testSendAndReceiveTextMessage.
@Test
public void testSendAndReceiveTextMessage() throws Exception {
topicConn.start();
TopicSession topicSession = topicConn.createTopicSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Topic topic = topicSession.createTopic(TOPIC_NAME);
TopicPublisher sender = topicSession.createPublisher(topic);
TopicSubscriber receiver1 = topicSession.createDurableSubscriber(topic, DURABLE_SUBSCRIBER_NAME);
TopicSubscriber receiver2 = topicSession.createSubscriber(topic);
sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = topicSession.createTextMessage(MESSAGE_TEXT_1);
sender.send(message);
assertEquals(MESSAGE_TEXT_1, ((TextMessage) receiver1.receive()).getText());
assertEquals(MESSAGE_TEXT_1, ((TextMessage) receiver2.receive()).getText());
topicSession.unsubscribe(DURABLE_SUBSCRIBER_NAME);
}
use of javax.jms.TopicPublisher in project qpid-broker-j by apache.
the class BDBUpgradeTest method testSelectorDurability.
/**
* Test that the selector applied to the DurableSubscription was successfully
* transferred to the new store, and functions as expected with continued use
* by monitoring message count while sending new messages to the topic and then
* consuming them.
*/
@Test
public void testSelectorDurability() throws Exception {
TopicConnection connection = getTopicConnection();
try {
connection.start();
TopicSession session = connection.createTopicSession(true, Session.SESSION_TRANSACTED);
Topic topic = session.createTopic(SELECTOR_TOPIC_NAME);
TopicPublisher publisher = session.createPublisher(topic);
int index = ThreadLocalRandom.current().nextInt();
Message messageA = session.createTextMessage("A");
messageA.setIntProperty("ID", index);
messageA.setStringProperty("testprop", "false");
publisher.publish(messageA);
Message messageB = session.createTextMessage("B");
messageB.setIntProperty("ID", index);
messageB.setStringProperty("testprop", "true");
publisher.publish(messageB);
session.commit();
TopicSubscriber subscriber = session.createDurableSubscriber(topic, SELECTOR_SUB_NAME, "testprop='true'", false);
Message migrated = subscriber.receive(getReceiveTimeout());
assertThat("Failed to receive migrated message", migrated, is(notNullValue()));
Message received = subscriber.receive(getReceiveTimeout());
session.commit();
assertThat("Failed to receive published message", received, is(notNullValue()));
assertThat("Message is not Text message", received, is(instanceOf(TextMessage.class)));
assertThat("Unexpected text", ((TextMessage) received).getText(), is(equalTo("B")));
assertThat("Unexpected index", received.getIntProperty("ID"), is(equalTo(index)));
session.close();
} finally {
connection.close();
}
}
use of javax.jms.TopicPublisher in project qpid-broker-j by apache.
the class BDBUpgradeTest method testDurableSubscriptionWithoutSelector.
/**
* Test that the DurableSubscription without selector was successfully
* transfered to the new store, and functions as expected with continued use.
*/
@Test
public void testDurableSubscriptionWithoutSelector() throws Exception {
TopicConnection connection = getTopicConnection();
try {
connection.start();
TopicSession session = connection.createTopicSession(true, Session.SESSION_TRANSACTED);
Topic topic = session.createTopic(TOPIC_NAME);
TopicPublisher publisher = session.createPublisher(topic);
int index = ThreadLocalRandom.current().nextInt();
Message messageA = session.createTextMessage("A");
messageA.setIntProperty("ID", index);
messageA.setStringProperty("testprop", "false");
publisher.publish(messageA);
Message messageB = session.createTextMessage("B");
messageB.setIntProperty("ID", index);
messageB.setStringProperty("testprop", "true");
publisher.publish(messageB);
session.commit();
TopicSubscriber subscriber = session.createDurableSubscriber(topic, SUB_NAME);
Message migrated = subscriber.receive(getReceiveTimeout());
assertThat("Failed to receive migrated message", migrated, is(notNullValue()));
Message receivedA = subscriber.receive(getReceiveTimeout());
session.commit();
assertThat("Failed to receive published message A", receivedA, is(notNullValue()));
assertThat("Message A is not Text message", receivedA, is(instanceOf(TextMessage.class)));
assertThat("Unexpected text for A", ((TextMessage) receivedA).getText(), is(equalTo("A")));
assertThat("Unexpected index", receivedA.getIntProperty("ID"), is(equalTo(index)));
Message receivedB = subscriber.receive(getReceiveTimeout());
session.commit();
assertThat("Failed to receive published message B", receivedB, is(notNullValue()));
assertThat("Message B is not Text message", receivedB, is(instanceOf(TextMessage.class)));
assertThat("Unexpected text for B", ((TextMessage) receivedB).getText(), is(equalTo("B")));
assertThat("Unexpected index for B", receivedB.getIntProperty("ID"), is(equalTo(index)));
session.commit();
session.close();
} finally {
connection.close();
}
}
Aggregations