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

The following examples show how to use javax.jms.BytesMessage#writeUTF() . 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: GeneralInteropTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void sendBytesMessageUsingCoreJms(String queueName, byte[] data) throws Exception {
   Connection jmsConn = null;
   try {
      jmsConn = coreCf.createConnection();
      Session session = jmsConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      BytesMessage bytesMessage = session.createBytesMessage();

      bytesMessage.writeBytes(data);
      bytesMessage.writeBoolean(true);
      bytesMessage.writeLong(99999L);
      bytesMessage.writeChar('h');
      bytesMessage.writeInt(987);
      bytesMessage.writeShort((short) 1099);
      bytesMessage.writeUTF("hellobytes");

      Queue queue = session.createQueue(queueName);
      MessageProducer producer = session.createProducer(queue);

      producer.send(bytesMessage);
   } finally {
      if (jmsConn != null) {
         jmsConn.close();
      }
   }

}
 
Example 2
Source File: GeneralInteropTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void sendBytesMessageUsingOpenWire(byte[] bytesData) throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);

   final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);

   BytesMessage bytesMessage = session.createBytesMessage();
   bytesMessage.writeBytes(bytesData);
   bytesMessage.writeBoolean(true);
   bytesMessage.writeLong(99999L);
   bytesMessage.writeChar('h');
   bytesMessage.writeInt(987);
   bytesMessage.writeShort((short) 1099);
   bytesMessage.writeUTF("hellobytes");

   producer.send(bytesMessage);
}
 
Example 3
Source File: BytesMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void prepareMessage(final Message m) throws JMSException {
   super.prepareMessage(m);

   BytesMessage bm = (BytesMessage) m;

   bm.writeBoolean(true);
   bm.writeByte((byte) 3);
   bm.writeBytes(new byte[]{(byte) 4, (byte) 5, (byte) 6});
   bm.writeChar((char) 7);
   bm.writeDouble(8.0);
   bm.writeFloat(9.0f);
   bm.writeInt(10);
   bm.writeLong(11L);
   bm.writeShort((short) 12);
   bm.writeUTF("this is an UTF String");
   bm.reset();
}
 
Example 4
Source File: JmsProduceMessageTypesTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testSendJMSBytesMessage() throws Exception {
    connection = createAmqpConnection();
    connection.start();

    String payload = "TEST";

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(name.getMethodName());
    MessageProducer producer = session.createProducer(queue);
    BytesMessage message = session.createBytesMessage();
    message.writeUTF(payload);
    producer.send(message);
    QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
    assertEquals(1, proxy.getQueueSize());

    MessageConsumer consumer = session.createConsumer(queue);
    Message received = consumer.receive(5000);
    assertNotNull(received);
    assertTrue(received instanceof BytesMessage);
    BytesMessage bytes = (BytesMessage) received;
    assertEquals(payload, bytes.readUTF());
}
 
Example 5
Source File: JmsTestRule.java    From brave with Apache License 2.0 4 votes vote down vote up
BytesMessage newBytesMessage(String text) throws JMSException {
  BytesMessage message = queueSession.createBytesMessage();
  message.writeUTF(text);
  return message;
}