Java Code Examples for javax.jms.BytesMessage#acknowledge()

The following examples show how to use javax.jms.BytesMessage#acknowledge() . 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: LargeMessageOverBridgeTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
/**
 * This was causing a text message to ber eventually converted into large message when sent over the bridge
 *
 * @throws Exception
 */
@Test
public void testSendBytesAsLargeOnBridgeOnly() throws Exception {
   createQueue(QUEUE);

   Queue queue = (Queue) context1.lookup("queue/" + QUEUE);
   Connection conn1 = cf1.createConnection();
   Session session1 = conn1.createSession(true, Session.SESSION_TRANSACTED);
   MessageProducer prod1 = session1.createProducer(queue);

   Connection conn2 = cf2.createConnection();
   Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer cons2 = session2.createConsumer(queue);
   conn2.start();

   byte[] bytes = new byte[10 * 1024];

   for (int i = 0; i < bytes.length; i++) {
      bytes[i] = getSamplebyte(i);
   }

   for (int i = 0; i < 10; i++) {
      BytesMessage msg = session1.createBytesMessage();
      msg.writeBytes(bytes);
      prod1.send(msg);
   }

   session1.commit();

   for (int i = 0; i < 5; i++) {
      BytesMessage msg2 = (BytesMessage) cons2.receive(5000);
      assertNotNull(msg2);
      msg2.acknowledge();

      for (int j = 0; j < bytes.length; j++) {
         assertEquals("Position " + i, msg2.readByte(), bytes[j]);
      }
   }

   conn1.close();
   conn2.close();
}
 
Example 2
Source File: LargeMessageOverBridgeTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
/**
 * The message won't be large to the client while it will be considered large through the bridge
 *
 * @throws Exception
 */
@Test
public void testSendLargeForBridge() throws Exception {
   createQueue(QUEUE);

   Queue queue = (Queue) context1.lookup("queue/" + QUEUE);

   ActiveMQConnectionFactory cf1 = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, generateInVMParams(1)));
   cf1.setMinLargeMessageSize(200 * 1024);

   Connection conn1 = cf1.createConnection();
   Session session1 = conn1.createSession(true, Session.SESSION_TRANSACTED);
   MessageProducer prod1 = session1.createProducer(queue);

   Connection conn2 = cf2.createConnection();
   Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer cons2 = session2.createConsumer(queue);
   conn2.start();

   byte[] bytes = new byte[150 * 1024];

   for (int i = 0; i < bytes.length; i++) {
      bytes[i] = getSamplebyte(i);
   }

   for (int i = 0; i < 10; i++) {
      BytesMessage msg = session1.createBytesMessage();
      msg.writeBytes(bytes);
      prod1.send(msg);
   }

   session1.commit();

   for (int i = 0; i < 5; i++) {
      BytesMessage msg2 = (BytesMessage) cons2.receive(5000);
      assertNotNull(msg2);
      msg2.acknowledge();

      for (int j = 0; j < bytes.length; j++) {
         assertEquals("Position " + i, msg2.readByte(), bytes[j]);
      }
   }

   conn1.close();
   conn2.close();
}