Java Code Examples for org.apache.activemq.artemis.api.core.client.ClientMessage#setAddress()

The following examples show how to use org.apache.activemq.artemis.api.core.client.ClientMessage#setAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SessionStopStartTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private int getMessageEncodeSize(final SimpleString address) throws Exception {
   ServerLocator locator = createInVMNonHALocator();
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession(false, true, true);
   ClientMessage message = session.createMessage(false);
   // we need to set the destination so we can calculate the encodesize correctly
   message.setAddress(address);
   int encodeSize = message.getEncodeSize();
   session.close();
   cf.close();
   return encodeSize;
}
 
Example 2
Source File: AckBatchSizeTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private int getMessageEncodeSize(final SimpleString address) throws Exception {
   ServerLocator locator = createInVMNonHALocator();
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession(false, true, true);
   ClientMessage message = session.createMessage(false);
   // we need to set the destination so we can calculate the encodesize correctly
   message.setAddress(address);
   int encodeSize = message.getEncodeSize();
   session.close();
   cf.close();
   return encodeSize;
}
 
Example 3
Source File: ConsumerWindowSizeTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private int getMessageEncodeSize(final SimpleString address) throws Exception {
   ServerLocator locator = createInVMNonHALocator();
   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession(false, true, true);
   ClientMessage message = session.createMessage(false);
   // we need to set the destination so we can calculate the encodesize correctly
   message.setAddress(address);
   int encodeSize = message.getEncodeSize();
   session.close();
   cf.close();
   return encodeSize;
}
 
Example 4
Source File: CoreClientTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
private void testCoreClient(final boolean netty, ServerLocator serverLocator) throws Exception {
   final SimpleString QUEUE = new SimpleString("CoreClientTestQueue");

   ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultConfig(netty), false));

   server.start();

   ServerLocator locator = serverLocator == null ? createNonHALocator(netty) : serverLocator;

   ClientSessionFactory sf = createSessionFactory(locator);

   ClientSession session = sf.createSession(false, true, true);

   session.createQueue(new QueueConfiguration(QUEUE).setDurable(false));

   ClientProducer producer = session.createProducer(QUEUE);

   final int numMessages = 1000;

   for (int i = 0; i < numMessages; i++) {
      ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);

      message.putStringProperty("foo", "bar");

      // One way around the setting destination problem is as follows -
      // Remove destination as an attribute from client producer.
      // The destination always has to be set explicitly before sending a message

      message.setAddress(QUEUE);

      message.getBodyBuffer().writeString("testINVMCoreClient");

      producer.send(message);
   }

   ClientConsumer consumer = session.createConsumer(QUEUE);

   session.start();

   for (int i = 0; i < numMessages; i++) {
      ClientMessage message2 = consumer.receive();

      ActiveMQBuffer buffer = message2.getBodyBuffer();

      Assert.assertEquals("testINVMCoreClient", buffer.readString());

      message2.acknowledge();
   }

   sf.close();
}