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

The following examples show how to use javax.jms.BytesMessage#setIntProperty() . 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: AmqpLargeMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void sendBytesMessages(int nMsgs, ConnectionFactory factory) throws Exception {
   try (Connection connection = factory.createConnection()) {
      Session session = connection.createSession();
      Queue queue = session.createQueue(testQueueName);
      MessageProducer producer = session.createProducer(queue);
      BytesMessage msg = session.createBytesMessage();

      StringBuilder builder = new StringBuilder();
      for (int i = 0; i < PAYLOAD; ++i) {
         builder.append("A");
      }

      msg.writeBytes(builder.toString().getBytes(StandardCharsets.UTF_8));

      for (int i = 0; i < nMsgs; ++i) {
         msg.setIntProperty("i", (Integer) i);
         producer.send(msg);
      }
   }
}
 
Example 2
Source File: JMSMessageGroupsTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void sendMessagesToBroker(String queueName, Connection connection, int count, AtomicInteger sequence) throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue queue = session.createQueue(queueName);
   MessageProducer producer = session.createProducer(queue);

   byte[] buffer = new byte[MESSAGE_SIZE];
   for (count = 0; count < MESSAGE_SIZE; count++) {
      String s = String.valueOf(count % 10);
      Character c = s.charAt(0);
      int value = c.charValue();
      buffer[count] = (byte) value;
   }

   LOG.debug("Sending {} messages to destination: {}", MESSAGE_COUNT, queue);
   for (int i = 1; i <= MESSAGE_COUNT; i++) {
      BytesMessage message = session.createBytesMessage();
      message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
      message.setStringProperty("JMSXGroupID", JMSX_GROUP_ID);
      message.setIntProperty("JMSXGroupSeq", sequence.incrementAndGet());
      message.writeBytes(buffer);
      producer.send(message);
   }

   session.close();
}
 
Example 3
Source File: JmsLargeMessagesInGroupsTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
protected void sendMessagesToBroker(int count, AtomicInteger sequence) throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(getDestinationName());
    MessageProducer producer = session.createProducer(queue);

    byte[] buffer = new byte[MESSAGE_SIZE];
    for (count = 0; count < MESSAGE_SIZE; count++) {
        String s = String.valueOf(count % 10);
        Character c = s.charAt(0);
        int value = c.charValue();
        buffer[count] = (byte) value;
    }

    LOG.info("Sending {} messages to destination: {}", MESSAGE_COUNT, queue);
    for (int i = 1; i <= MESSAGE_COUNT; i++) {
        BytesMessage message = session.createBytesMessage();
        message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
        message.setStringProperty("JMSXGroupID", JMSX_GROUP_ID);
        message.setIntProperty("JMSXGroupSeq", sequence.incrementAndGet());
        message.writeBytes(buffer);
        producer.send(message);
    }

    producer.close();
}
 
Example 4
Source File: OverflowPolicyTestBase.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
protected Message nextMessage(int index, Session producerSession) throws JMSException
{
    BytesMessage send = producerSession.createBytesMessage();
    send.writeBytes(BYTE_300);
    send.setIntProperty(INDEX, index);
    return send;
}
 
Example 5
Source File: JMSObjectInputOperatorTest.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
private void createByteMsgs(int numMessages) throws Exception
{
  BytesMessage message = testMeta.session.createBytesMessage();
  for (int i = 0; i < numMessages; i++) {
    message.writeBytes(("Message: " + i).getBytes());
    message.setIntProperty("counter", i);
    message.setJMSCorrelationID("MyCorrelationID");
    message.setJMSReplyTo(new ActiveMQQueue("MyReplyTo"));
    message.setJMSType("MyType");
    message.setJMSPriority(5);
    testMeta.producer.send(message);
  }
}
 
Example 6
Source File: StompTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubscribeWithMessageSentWithProperties() throws Exception {
   conn.connect(defUser, defPass);
   subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO);

   MessageProducer producer = session.createProducer(queue);
   BytesMessage message = session.createBytesMessage();
   message.setStringProperty("S", "value");
   message.setBooleanProperty("n", false);
   message.setByteProperty("byte", (byte) 9);
   message.setDoubleProperty("d", 2.0);
   message.setFloatProperty("f", (float) 6.0);
   message.setIntProperty("i", 10);
   message.setLongProperty("l", 121);
   message.setShortProperty("s", (short) 12);
   message.writeBytes("Hello World".getBytes(StandardCharsets.UTF_8));
   producer.send(message);

   ClientStompFrame frame = conn.receiveFrame(10000);
   Assert.assertNotNull(frame);
   Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
   Assert.assertEquals("value", frame.getHeader("S"));
   Assert.assertEquals("false", frame.getHeader("n"));
   Assert.assertEquals("9", frame.getHeader("byte"));
   Assert.assertEquals("2.0", frame.getHeader("d"));
   Assert.assertEquals("6.0", frame.getHeader("f"));
   Assert.assertEquals("10", frame.getHeader("i"));
   Assert.assertEquals("121", frame.getHeader("l"));
   Assert.assertEquals("12", frame.getHeader("s"));
   Assert.assertEquals("Hello World", frame.getBody());

   conn.disconnect();
}
 
Example 7
Source File: StompV11Test.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubscribeWithMessageSentWithProperties() throws Exception {
   conn.connect(defUser, defPass);

   subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);

   MessageProducer producer = session.createProducer(queue);
   BytesMessage message = session.createBytesMessage();
   message.setStringProperty("S", "value");
   message.setBooleanProperty("n", false);
   message.setByteProperty("byte", (byte) 9);
   message.setDoubleProperty("d", 2.0);
   message.setFloatProperty("f", (float) 6.0);
   message.setIntProperty("i", 10);
   message.setLongProperty("l", 121);
   message.setShortProperty("s", (short) 12);
   message.writeBytes("Hello World".getBytes(StandardCharsets.UTF_8));
   producer.send(message);

   ClientStompFrame frame = conn.receiveFrame();
   Assert.assertNotNull(frame);

   Assert.assertTrue(frame.getHeader("S") != null);
   Assert.assertTrue(frame.getHeader("n") != null);
   Assert.assertTrue(frame.getHeader("byte") != null);
   Assert.assertTrue(frame.getHeader("d") != null);
   Assert.assertTrue(frame.getHeader("f") != null);
   Assert.assertTrue(frame.getHeader("i") != null);
   Assert.assertTrue(frame.getHeader("l") != null);
   Assert.assertTrue(frame.getHeader("s") != null);
   Assert.assertEquals("Hello World", frame.getBody());

   conn.disconnect();
}
 
Example 8
Source File: StompV12Test.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubscribeWithMessageSentWithProperties() throws Exception {
   conn.connect(defUser, defPass);

   subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);

   MessageProducer producer = session.createProducer(queue);
   BytesMessage message = session.createBytesMessage();
   message.setStringProperty("S", "value");
   message.setBooleanProperty("n", false);
   message.setByteProperty("byte", (byte) 9);
   message.setDoubleProperty("d", 2.0);
   message.setFloatProperty("f", (float) 6.0);
   message.setIntProperty("i", 10);
   message.setLongProperty("l", 121);
   message.setShortProperty("s", (short) 12);
   message.writeBytes("Hello World".getBytes(StandardCharsets.UTF_8));
   producer.send(message);

   ClientStompFrame frame = conn.receiveFrame();
   Assert.assertNotNull(frame);

   Assert.assertTrue(frame.getHeader("S") != null);
   Assert.assertTrue(frame.getHeader("n") != null);
   Assert.assertTrue(frame.getHeader("byte") != null);
   Assert.assertTrue(frame.getHeader("d") != null);
   Assert.assertTrue(frame.getHeader("f") != null);
   Assert.assertTrue(frame.getHeader("i") != null);
   Assert.assertTrue(frame.getHeader("l") != null);
   Assert.assertTrue(frame.getHeader("s") != null);
   Assert.assertEquals("Hello World", frame.getBody());

   conn.disconnect();
}
 
Example 9
Source File: JmsTempDestinationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test temp queue works under load
 *
 * @throws JMSException
 */
@Test
public void testTmpQueueWorksUnderLoad() throws JMSException {
   int count = 500;
   int dataSize = 1024;

   ArrayList<BytesMessage> list = new ArrayList<>(count);
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue queue = session.createTemporaryQueue();
   MessageProducer producer = session.createProducer(queue);
   producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

   byte[] data = new byte[dataSize];
   for (int i = 0; i < count; i++) {
      BytesMessage message = session.createBytesMessage();
      message.writeBytes(data);
      message.setIntProperty("c", i);
      producer.send(message);
      list.add(message);
   }

   connection.start();
   MessageConsumer consumer = session.createConsumer(queue);
   for (int i = 0; i < count; i++) {
      Message message2 = consumer.receive(2000);
      Assert.assertTrue(message2 != null);
      Assert.assertEquals(i, message2.getIntProperty("c"));
      Assert.assertTrue(message2.equals(list.get(i)));
   }
}
 
Example 10
Source File: JMSMessageTypesTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private void testBytesMessageSendReceive(Connection producerConnection, Connection consumerConnection) throws Throwable {
   long time = System.currentTimeMillis();

   Session session = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue queue = session.createQueue(getQueueName());

   byte[] bytes = new byte[0xf + 1];
   for (int i = 0; i <= 0xf; i++) {
      bytes[i] = (byte) i;
   }

   MessageProducer producer = session.createProducer(queue);
   for (int i = 0; i < NUM_MESSAGES; i++) {
      instanceLog.debug("Sending " + i);
      BytesMessage message = session.createBytesMessage();

      message.writeBytes(bytes);
      message.setIntProperty("count", i);
      producer.send(message);
   }

   Session sessionConsumer = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue consumerQueue = sessionConsumer.createQueue(getQueueName());
   final MessageConsumer consumer = sessionConsumer.createConsumer(consumerQueue);

   for (int i = 0; i < NUM_MESSAGES; i++) {
      BytesMessage m = (BytesMessage) consumer.receive(5000);
      Assert.assertNotNull("Could not receive message count=" + i + " on consumer", m);

      m.reset();

      long size = m.getBodyLength();
      byte[] bytesReceived = new byte[(int) size];
      m.readBytes(bytesReceived);

      instanceLog.debug("Received " + ByteUtil.bytesToHex(bytesReceived, 1) + " count - " + m.getIntProperty("count"));

      Assert.assertArrayEquals(bytes, bytesReceived);
   }

   long taken = (System.currentTimeMillis() - time) / 1000;
   instanceLog.debug("taken = " + taken);
}
 
Example 11
Source File: IMSSender.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Override
public javax.jms.Message createMessage(Session session, String correlationID, String message) throws NamingException, JMSException {
	
	BytesMessage bytesMessage = null;
	bytesMessage = session.createBytesMessage();
	
	setMessageCorrelationID(bytesMessage, correlationID);
	
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	
	try {
		bos.write(IIH_HEADER_STRUCT_ID.getBytes(CHARSET));
		bos.write(intToBytes(IIH_HEADER_VERSION));
		bos.write(intToBytes(IIH_HEADER_LENGTH));
		bos.write(intToBytes(IIH_HEADER_ENCODING));
		bos.write(intToBytes(IIH_HEADER_CODECHARSET));
		bos.write(IIH_HEADER_FORMAT.getBytes(CHARSET));
		bos.write(intToBytes(IIH_HEADER_FLAGS));
		bos.write(IIH_HEADER_LTERM_OR.getBytes(CHARSET));
		bos.write(IIH_HEADER_MFS_MAPNAME.getBytes(CHARSET));
		bos.write(IIH_HEADER_REPLY_FORMAT.getBytes(CHARSET));
		bos.write(IIH_HEADER_MFS_AUTH.getBytes(CHARSET));
		bos.write(IIH_HEADER_TRAN_INSTANCE);
		bos.write(IIH_HEADER_TRAN_STATE.getBytes(CHARSET));
		bos.write(IIH_HEADER_COMMIT_MODE.getBytes(CHARSET));
		bos.write(IIH_HEADER_SECURITY_SCOPE.getBytes(CHARSET));
		bos.write(IIH_HEADER_RESERVED.getBytes(CHARSET));
		
		byte[] data = message.getBytes(CHARSET);

		bos.write(shortToBytes(data.length + 13)); //LL, +13 is for LL, ZZ and transaction code bytes
		bos.write(new byte[2]); //ZZ
		bos.write((transactionCode + " ").getBytes(CHARSET));
		
		bos.write(data);
		
		bos.toByteArray();
	} catch (IOException e) {
		// Should never happen
		throw new RuntimeException(e);
	}
	
	bytesMessage.writeBytes(bos.toByteArray());
	
	// Set Properties
	bytesMessage.setIntProperty("JMS_IBM_Encoding", MQENC_NATIVE);
	bytesMessage.setIntProperty("JMS_IBM_Character_Set", CCSID_ISO_8859_1);	
	bytesMessage.setStringProperty("JMS_IBM_Format", MQC_MQFMT_IMS);	

	return bytesMessage;
}