use of org.apache.activemq.artemis.jms.client.ActiveMQQueue in project activemq-artemis by apache.
the class BrokerPluginExample method sendConsumeCore.
private static void sendConsumeCore() throws JMSException {
Connection connection = null;
try {
// Perform a lookup on the Connection Factory
ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
Queue queue = new ActiveMQQueue("exampleQueue");
// Create a JMS Connection
connection = cf.createConnection();
// Create a JMS Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create a JMS Message Producer
MessageProducer producer = session.createProducer(queue);
// Create a Text Message
TextMessage message = session.createTextMessage("This is a text message");
// Send the Message
producer.send(message);
// Create a JMS Message Consumer
MessageConsumer messageConsumer = session.createConsumer(queue);
// Start the Connection
connection.start();
// Receive the message
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
if (messageReceived.getStringProperty("count") == null) {
throw new RuntimeException(("missed property count"));
}
System.out.println("message = " + messageReceived.getText() + " property count (added by interceptor = " + messageReceived.getStringProperty("count") + ")");
} finally {
if (connection != null) {
connection.close();
}
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQQueue in project pentaho-kettle by pentaho.
the class ActiveMQProvider method getDestination.
@Override
public Destination getDestination(JmsDelegate delegate) {
checkNotNull(delegate.destinationName, getString(PKG, "JmsWebsphereMQ.DestinationNameRequired"));
String destName = delegate.destinationName;
return isQueue(delegate) ? new ActiveMQQueue(destName) : new ActiveMQTopic(destName);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQQueue in project pentaho-kettle by pentaho.
the class ActiveMQProvider method getDestination.
@Override
public Destination getDestination(JmsDelegate delegate, VariableSpace variableSpace) {
checkNotNull(delegate.destinationName, getString(JmsConstants.PKG, "JmsWebsphereMQ.DestinationNameRequired"));
String destName = variableSpace.environmentSubstitute(delegate.destinationName);
return isQueue(delegate, variableSpace) ? new ActiveMQQueue(destName) : new ActiveMQTopic(destName);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQQueue in project activemq-artemis by apache.
the class HornetQProtocolManagerTest method testLegacy2.
/**
* This test will use an ArtemisConnectionFactory with clientProtocolManager=
*/
@Test
public void testLegacy2() throws Exception {
ConnectionFactoryConfiguration configuration = new ConnectionFactoryConfigurationImpl();
configuration.setConnectorNames("legacy");
configuration.setName("legacy");
configuration.setProtocolManagerFactoryStr(HornetQClientProtocolManagerFactory.class.getName());
embeddedJMS.getJMSServerManager().createConnectionFactory(false, configuration, "legacy");
// WORKAROUND: the 2.0.0 broker introduced addressing change and the 2.2.0 broker added compatibility for old
// client libraries relying on the legacy prefixes. The new client being used in this test needs prefix explicitly.
Queue queue = new ActiveMQQueue("jms.queue.testQueue");
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) embeddedJMS.lookup("legacy");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage("Test");
for (int i = 0; i < 5; i++) {
message.setStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), "duplicate");
producer.send(message);
}
connection.start();
MessageConsumer consumer = session.createConsumer(queue);
TextMessage messageRec = (TextMessage) consumer.receive(5000);
Assert.assertNotNull(messageRec);
Assert.assertEquals("Test", messageRec.getText());
Assert.assertNull(consumer.receiveNoWait());
connection.close();
connectionFactory.close();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQQueue in project activemq-artemis by apache.
the class ReferenceableTest method testReferenceQueue.
@Test
public void testReferenceQueue() throws Exception {
Reference queueRef = ((Referenceable) queue1).getReference();
String factoryName = queueRef.getFactoryClassName();
Class<?> factoryClass = Class.forName(factoryName);
ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
Object instance = factory.getObjectInstance(queueRef, null, null, null);
ProxyAssertSupport.assertTrue(instance instanceof ActiveMQDestination);
ActiveMQQueue queue2 = (ActiveMQQueue) instance;
ProxyAssertSupport.assertEquals(queue1.getQueueName(), queue2.getQueueName());
simpleSendReceive(cf, queue2);
}
Aggregations