use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class ExclusiveTest method testExclusiveQueueConsumerSettingUsingAddressQueueParameters.
@Test
public void testExclusiveQueueConsumerSettingUsingAddressQueueParameters() throws Exception {
ConnectionFactory fact = getCF();
Connection connection = fact.createConnection();
try {
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Queue queue = session.createQueue("random?exclusive=true");
assertEquals("random", queue.getQueueName());
ActiveMQDestination a = (ActiveMQDestination) queue;
assertTrue(a.getQueueAttributes().getExclusive());
MessageProducer producer = session.createProducer(queue);
MessageConsumer consumer1 = session.createConsumer(queue);
MessageConsumer consumer2 = session.createConsumer(queue);
MessageConsumer consumer3 = session.createConsumer(queue);
connection.start();
for (int j = 0; j < 100; j++) {
TextMessage message = session.createTextMessage();
message.setText("Message" + j);
producer.send(message);
}
// All msgs should go to the first consumer
for (int j = 0; j < 100; j++) {
TextMessage tm = (TextMessage) consumer1.receive(10000);
assertNotNull(tm);
assertEquals("Message" + j, tm.getText());
tm = (TextMessage) consumer2.receiveNoWait();
assertNull(tm);
tm = (TextMessage) consumer3.receiveNoWait();
assertNull(tm);
}
} finally {
connection.close();
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class AMQPToJMSCoreTest method testMessageDestination.
@Test
public void testMessageDestination() throws Exception {
System.out.println("foo");
AmqpClient client = new AmqpClient(new URI("tcp://127.0.0.1:61616"), null, null);
AmqpConnection amqpconnection = client.connect();
try {
AmqpSession session = amqpconnection.createSession();
AmqpSender sender = session.createSender(queueName);
AmqpMessage message = new AmqpMessage();
message.setMessageId("MessageID:" + 0);
// message.setApplicationProperty("_AMQ_ROUTING_TYPE", (byte) 1);
message.getWrappedMessage().setHeader(new Header());
message.getWrappedMessage().getHeader().setDeliveryCount(new UnsignedInteger(2));
sender.send(message);
} finally {
amqpconnection.close();
}
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
Connection connection = null;
try {
connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createQueue(queueName));
connection.start();
Message message = consumer.receive(2000);
Assert.assertNotNull(message);
ActiveMQDestination jmsDestination = (ActiveMQDestination) message.getJMSDestination();
Assert.assertEquals(queueName, jmsDestination.getAddress());
} finally {
if (connection != null) {
connection.close();
}
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class ResourceAdapterTest method testStartActivation.
@Test
public void testStartActivation() throws Exception {
ActiveMQServer server = createServer(false);
try {
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory factory = createSessionFactory(locator);
ClientSession session = factory.createSession(false, false, false);
ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue("test");
session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), true);
session.close();
ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
ra.setUserName("userGlobal");
ra.setPassword("passwordGlobal");
ra.start(new BootstrapContext());
Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection();
conn.close();
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setResourceAdapter(ra);
spec.setUseJNDI(false);
spec.setUser("user");
spec.setPassword("password");
spec.setDestinationType("javax.jms.Topic");
spec.setDestination("test");
spec.setMinSession(1);
spec.setMaxSession(1);
ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
activation.start();
activation.stop();
ra.stop();
locator.close();
} finally {
server.stop();
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class ObjectFactoryTest method testDestination.
@Test(timeout = 1000)
public void testDestination() throws Exception {
// Create sample destination
ActiveMQDestination dest = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString());
// Create reference
Reference ref = JNDIReferenceFactory.createReference(dest.getClass().getName(), dest);
// Get object created based on reference
ActiveMQDestination temp;
JNDIReferenceFactory refFactory = new JNDIReferenceFactory();
temp = (ActiveMQDestination) refFactory.getObjectInstance(ref, null, null, null);
// Check settings
assertEquals(dest.getAddress(), temp.getAddress());
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class DestinationObjectFactoryTest method testReference.
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testReference() throws Exception {
ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString());
Reference reference = queue.getReference();
String factoryName = reference.getFactoryClassName();
Class<?> factoryClass = Class.forName(factoryName);
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
Object object = factory.getObjectInstance(reference, null, null, null);
Assert.assertNotNull(object);
Assert.assertTrue(object instanceof ActiveMQDestination);
Assert.assertEquals(queue, object);
}
Aggregations