use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class SimpleOpenWireTest method testMixedOpenWireExample.
@Test
public void testMixedOpenWireExample() throws Exception {
Connection openConn = null;
SimpleString durableQueue = new SimpleString("exampleQueue");
this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
ActiveMQConnectionFactory openCF = new ActiveMQConnectionFactory();
Queue queue = new ActiveMQQueue("exampleQueue");
openConn = openCF.createConnection();
openConn.start();
Session openSession = openConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = openSession.createProducer(queue);
TextMessage message = openSession.createTextMessage("This is a text message");
producer.send(message);
org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory artemisCF = new org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory();
Connection artemisConn = artemisCF.createConnection();
Session artemisSession = artemisConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
artemisConn.start();
MessageConsumer messageConsumer = artemisSession.createConsumer(artemisSession.createQueue("exampleQueue"));
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
assertEquals("This is a text message", messageReceived.getText());
openConn.close();
artemisConn.close();
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class SimpleOpenWireTest method testSendEmptyMessages.
@Test
public void testSendEmptyMessages() throws Exception {
Queue dest = new ActiveMQQueue(queueName);
QueueSession defaultQueueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender defaultSender = defaultQueueSession.createSender(dest);
defaultSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
connection.start();
Message msg = defaultQueueSession.createMessage();
msg.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(msg);
QueueReceiver queueReceiver = defaultQueueSession.createReceiver(dest);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
// bytes
BytesMessage bytesMessage = defaultQueueSession.createBytesMessage();
bytesMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(bytesMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
// map
MapMessage mapMessage = defaultQueueSession.createMapMessage();
mapMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(mapMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
// object
ObjectMessage objMessage = defaultQueueSession.createObjectMessage();
objMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(objMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
// stream
StreamMessage streamMessage = defaultQueueSession.createStreamMessage();
streamMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(streamMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
// text
TextMessage textMessage = defaultQueueSession.createTextMessage();
textMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(textMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class SimpleOpenWireTest method testOpenWireExample.
/**
* This is the example shipped with the distribution
*
* @throws Exception
*/
@Test
public void testOpenWireExample() throws Exception {
Connection exConn = null;
SimpleString durableQueue = new SimpleString("exampleQueue");
this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
try {
ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
Queue queue = new ActiveMQQueue(durableQueueName);
exConn = exFact.createConnection();
exConn.start();
Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage("This is a text message");
producer.send(message);
MessageConsumer messageConsumer = session.createConsumer(queue);
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
assertEquals("This is a text message", messageReceived.getText());
} finally {
if (exConn != null) {
exConn.close();
}
}
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class SimpleOpenWireTest method testAutoDestinationCreationOnProducerSend.
@Test
public void testAutoDestinationCreationOnProducerSend() throws JMSException {
AddressSettings addressSetting = new AddressSettings();
addressSetting.setAutoCreateQueues(true);
addressSetting.setAutoCreateAddresses(true);
String address = "foo";
server.getAddressSettingsRepository().addMatch(address, addressSetting);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TextMessage message = session.createTextMessage("bar");
Queue queue = new ActiveMQQueue(address);
MessageProducer producer = session.createProducer(null);
producer.send(queue, message);
MessageConsumer consumer = session.createConsumer(queue);
TextMessage message1 = (TextMessage) consumer.receive(1000);
assertTrue(message1.getText().equals(message.getText()));
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class RedeliveryPolicyTest method testNornalRedeliveryPolicyDelaysDeliveryOnRollback.
/**
* @throws Exception
*/
@Test
public void testNornalRedeliveryPolicyDelaysDeliveryOnRollback() throws Exception {
// Receive a message with the JMS API
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(0);
policy.setRedeliveryDelay(500);
connection.start();
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
ActiveMQQueue destination = new ActiveMQQueue("testNornalRedeliveryPolicyDelaysDeliveryOnRollback");
this.makeSureCoreQueueExist("testNornalRedeliveryPolicyDelaysDeliveryOnRollback");
MessageProducer producer = session.createProducer(destination);
MessageConsumer consumer = session.createConsumer(destination);
// Send the messages
producer.send(session.createTextMessage("1st"));
producer.send(session.createTextMessage("2nd"));
session.commit();
TextMessage m;
m = (TextMessage) consumer.receive(1000);
assertNotNull(m);
assertEquals("1st", m.getText());
session.rollback();
// No delay on first rollback..
m = (TextMessage) consumer.receive(100);
assertNotNull(m);
session.rollback();
// Show subsequent re-delivery delay is incrementing.
m = (TextMessage) consumer.receive(100);
assertNull(m);
m = (TextMessage) consumer.receive(700);
assertNotNull(m);
assertEquals("1st", m.getText());
session.rollback();
// The message gets redelivered after 500 ms every time since
// we are not using exponential backoff.
m = (TextMessage) consumer.receive(100);
assertNull(m);
m = (TextMessage) consumer.receive(700);
assertNotNull(m);
assertEquals("1st", m.getText());
}
Aggregations