当前位置: 首页>>代码示例>>Java>>正文


Java StreamMessage类代码示例

本文整理汇总了Java中javax.jms.StreamMessage的典型用法代码示例。如果您正苦于以下问题:Java StreamMessage类的具体用法?Java StreamMessage怎么用?Java StreamMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StreamMessage类属于javax.jms包,在下文中一共展示了StreamMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convert

import javax.jms.StreamMessage; //导入依赖的package包/类
/**
 * This implementation converts a TextMessage back to a String, a
 * ByteMessage back to a byte array, a MapMessage back to a Map,
 * and an ObjectMessage back to a Serializable object. Returns
 * the plain Message object in case of an unknown message type.
 *
 * @return payload
 * @throws javax.jms.JMSException
 */
@Override
public Object convert(Message message) throws JMSException
{
  if (message instanceof TextMessage) {
    return ((TextMessage)message).getText();
  } else if (message instanceof StreamMessage) {
    return ((StreamMessage)message).readString();
  } else if (message instanceof BytesMessage) {
    return extractByteArrayFromMessage((BytesMessage)message);
  } else if (message instanceof MapMessage) {
    return extractMapFromMessage((MapMessage)message);
  } else if (message instanceof ObjectMessage) {
    return extractSerializableFromMessage((ObjectMessage)message);
  } else {
    return message;
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:27,代码来源:JMSObjectInputOperator.java

示例2: handle

import javax.jms.StreamMessage; //导入依赖的package包/类
/**
 * Handle received message. Please note that ByteMessage (without object
 * mapping) and StreamMessage are not managed by the listener.
 *
 * @param message Spring generic message representation of the JMS message.
 * @param session The JMS Session if needed.
 * @param jmsMessage the original JMS message if needed.
 * @return String Message to send back or null if none
 */
public String handle(Message<?> message, Session session, javax.jms.Message jmsMessage) {
  if (message.getPayload() instanceof byte[] || message.getPayload() instanceof StreamMessage) {
    throw new IllegalArgumentException("Message payload type cannot be processed by this listener (" + message.getPayload().getClass().getName() + ")");
  }

  logger.debug("Received message: {}", message.getPayload().toString());

  // Extract data
  Map<String, Object> dataEntries = mapPayloadToData(message.getPayload());

  // Process W4 action
  String returnedMessage = processW4Action(message.getHeaders(), dataEntries);

  return returnedMessage;
}
 
开发者ID:benjamin-cartereau,项目名称:w4-bpmnplus-module-jms,代码行数:25,代码来源:AbstractW4MessageListener.java

示例3: testSendStreamMessage

import javax.jms.StreamMessage; //导入依赖的package包/类
@Test
public void testSendStreamMessage() throws JMSException, InterruptedException {
   JmsProducerCompletionListenerTest.CountingCompletionListener cl = new JmsProducerCompletionListenerTest.CountingCompletionListener(1);
   JMSProducer producer = context.createProducer();
   producer.setAsync(cl);
   StreamMessage msg = context.createStreamMessage();
   msg.setStringProperty("name", name.getMethodName());
   String bprop = "booleanProp";
   String iprop = "intProp";
   msg.setBooleanProperty(bprop, true);
   msg.setIntProperty(iprop, 42);
   msg.writeBoolean(true);
   msg.writeInt(67);
   producer.send(queue1, msg);
   JMSConsumer consumer = context.createConsumer(queue1);
   Message msg2 = consumer.receive(100);
   Assert.assertNotNull(msg2);
   Assert.assertTrue(cl.completionLatch.await(1, TimeUnit.SECONDS));
   StreamMessage sm = (StreamMessage) cl.lastMessage;
   Assert.assertEquals(true, sm.getBooleanProperty(bprop));
   Assert.assertEquals(42, sm.getIntProperty(iprop));
   Assert.assertEquals(true, sm.readBoolean());
   Assert.assertEquals(67, sm.readInt());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:25,代码来源:JmsContextTest.java

示例4: sendCompressedStreamMessageUsingOpenWire

import javax.jms.StreamMessage; //导入依赖的package包/类
private void sendCompressedStreamMessageUsingOpenWire() throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);

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

   StreamMessage streamMessage = session.createStreamMessage();

   streamMessage.writeBoolean(true);
   streamMessage.writeByte((byte) 10);
   streamMessage.writeBytes(TEXT.getBytes());
   streamMessage.writeChar('A');
   streamMessage.writeDouble(55.3D);
   streamMessage.writeFloat(79.1F);
   streamMessage.writeInt(37);
   streamMessage.writeLong(56652L);
   streamMessage.writeObject(new String("VVVV"));
   streamMessage.writeShort((short) 333);
   streamMessage.writeString(TEXT);

   producer.send(streamMessage);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:23,代码来源:CompressedInteropTest.java

示例5: sendStreamMessageUsingOpenWire

import javax.jms.StreamMessage; //导入依赖的package包/类
private void sendStreamMessageUsingOpenWire(String queueName) throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);

   System.out.println("destination: " + destination);
   final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);

   StreamMessage streamMessage = session.createStreamMessage();
   streamMessage.writeBoolean(true);
   streamMessage.writeByte((byte) 2);
   streamMessage.writeBytes(new byte[]{6, 7});
   streamMessage.writeChar('b');
   streamMessage.writeDouble(6.5);
   streamMessage.writeFloat((float) 93.9);
   streamMessage.writeInt(7657);
   streamMessage.writeLong(239999L);
   streamMessage.writeShort((short) 34222);
   streamMessage.writeString("hello streammessage");

   producer.send(streamMessage);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:22,代码来源:GeneralInteropTest.java

示例6: testStreamMessageSendReceive

import javax.jms.StreamMessage; //导入依赖的package包/类
private void testStreamMessageSendReceive(Connection producerConnection, Connection consumerConnection) throws Throwable {
   Session session = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue queue = session.createQueue(getQueueName());

   MessageProducer producer = session.createProducer(queue);
   for (int i = 0; i < NUM_MESSAGES; i++) {
      StreamMessage message = session.createStreamMessage();
      message.writeInt(i);
      message.writeBoolean(true);
      message.writeString("test");
      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++) {
      StreamMessage m = (StreamMessage) consumer.receive(5000);
      Assert.assertNotNull("Could not receive message count=" + i + " on consumer", m);

      Assert.assertEquals(i, m.readInt());
      Assert.assertEquals(true, m.readBoolean());
      Assert.assertEquals("test", m.readString());
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:27,代码来源:JMSMessageTypesTest.java

示例7: testStreamMessageCompression

import javax.jms.StreamMessage; //导入依赖的package包/类
@Test
public void testStreamMessageCompression() throws Exception {

   MessageConsumer consumer1 = remoteSession.createConsumer(included);
   MessageProducer producer = localSession.createProducer(included);
   producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

   waitForConsumerRegistration(localBroker, 1, included);

   StreamMessage test = localSession.createStreamMessage();

   for (int i = 0; i < 100; ++i) {
      test.writeString("test string: " + i);
   }

   producer.send(test);
   Message msg = consumer1.receive(RECEIVE_TIMEOUT_MILLS);
   assertNotNull(msg);
   ActiveMQStreamMessage message = (ActiveMQStreamMessage) msg;
   assertTrue(message.isCompressed());

   for (int i = 0; i < 100; ++i) {
      assertEquals("test string: " + i, message.readString());
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:26,代码来源:CompressionOverNetworkTest.java

示例8: sendTestStreamMessage

import javax.jms.StreamMessage; //导入依赖的package包/类
private void sendTestStreamMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
   ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = session.createProducer(queue);
   StreamMessage streamMessage = session.createStreamMessage();

   streamMessage.writeBoolean(true);
   streamMessage.writeByte((byte) 10);
   streamMessage.writeBytes(TEXT.getBytes());
   streamMessage.writeChar('A');
   streamMessage.writeDouble(55.3D);
   streamMessage.writeFloat(79.1F);
   streamMessage.writeInt(37);
   streamMessage.writeLong(56652L);
   streamMessage.writeObject(new String("VVVV"));
   streamMessage.writeShort((short) 333);
   streamMessage.writeString(TEXT);

   producer.send(streamMessage);
   connection.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:22,代码来源:MessageCompressionTest.java

示例9: testStreamMessage_2

import javax.jms.StreamMessage; //导入依赖的package包/类
/**
 * Send a <code>StreamMessage</code> with 2 Java primitives in its body (a <code>
 * String</code> and a <code>double</code>).
 * <br />
 * Receive it and test that the values of the primitives of the body are correct
 */
@Test
public void testStreamMessage_2() {
   try {
      StreamMessage message = senderSession.createStreamMessage();
      message.writeString("pi");
      message.writeDouble(3.14159);
      sender.send(message);

      Message m = receiver.receive(TestConfig.TIMEOUT);
      Assert.assertTrue("The message should be an instance of StreamMessage.\n", m instanceof StreamMessage);
      StreamMessage msg = (StreamMessage) m;
      Assert.assertEquals("pi", msg.readString());
      Assert.assertEquals(3.14159, msg.readDouble(), 0);
   } catch (JMSException e) {
      fail(e);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:24,代码来源:MessageTypeTest.java

示例10: assertEquivalent

import javax.jms.StreamMessage; //导入依赖的package包/类
@Override
protected void assertEquivalent(final Message m, final int mode, final boolean redelivery) throws JMSException {
   super.assertEquivalent(m, mode, redelivery);

   StreamMessage sm = (StreamMessage) m;

   ProxyAssertSupport.assertTrue(sm.readBoolean());

   byte[] bytes = new byte[5];
   sm.readBytes(bytes);
   String s = new String(bytes);
   ProxyAssertSupport.assertEquals("jboss", s);
   ProxyAssertSupport.assertEquals(-1, sm.readBytes(bytes));

   ProxyAssertSupport.assertEquals(sm.readChar(), 'c');
   ProxyAssertSupport.assertEquals(sm.readDouble(), 1.0D, 0.0D);
   ProxyAssertSupport.assertEquals(sm.readFloat(), 2.0F, 0.0F);
   ProxyAssertSupport.assertEquals(sm.readInt(), 3);
   ProxyAssertSupport.assertEquals(sm.readLong(), 4L);
   ProxyAssertSupport.assertEquals(sm.readObject(), "object");
   ProxyAssertSupport.assertEquals(sm.readShort(), (short) 5);
   ProxyAssertSupport.assertEquals(sm.readString(), "stringvalue");
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:24,代码来源:ForeignStreamMessageTest.java

示例11: prepareMessage

import javax.jms.StreamMessage; //导入依赖的package包/类
@Override
protected void prepareMessage(final Message m) throws JMSException {
   super.prepareMessage(m);

   StreamMessage sm = (StreamMessage) m;

   sm.writeBoolean(true);
   sm.writeByte((byte) 3);
   sm.writeBytes(new byte[]{(byte) 4, (byte) 5, (byte) 6});
   sm.writeChar((char) 7);
   sm.writeDouble(8.0);
   sm.writeFloat(9.0f);
   sm.writeInt(10);
   sm.writeLong(11L);
   sm.writeObject("this is an object");
   sm.writeShort((short) 12);
   sm.writeString("this is a String");
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:19,代码来源:StreamMessageTest.java

示例12: assertEquivalent

import javax.jms.StreamMessage; //导入依赖的package包/类
@Override
protected void assertEquivalent(final Message m, final int mode, final boolean redelivery) throws JMSException {
   super.assertEquivalent(m, mode, redelivery);

   StreamMessage sm = (StreamMessage) m;

   sm.reset();

   ProxyAssertSupport.assertEquals(true, sm.readBoolean());
   ProxyAssertSupport.assertEquals((byte) 3, sm.readByte());
   byte[] bytes = new byte[3];
   sm.readBytes(bytes);
   ProxyAssertSupport.assertEquals((byte) 4, bytes[0]);
   ProxyAssertSupport.assertEquals((byte) 5, bytes[1]);
   ProxyAssertSupport.assertEquals((byte) 6, bytes[2]);
   ProxyAssertSupport.assertEquals(-1, sm.readBytes(bytes));
   ProxyAssertSupport.assertEquals((char) 7, sm.readChar());
   ProxyAssertSupport.assertEquals(new Double(8.0), new Double(sm.readDouble()));
   ProxyAssertSupport.assertEquals(new Float(9.0), new Float(sm.readFloat()));
   ProxyAssertSupport.assertEquals(10, sm.readInt());
   ProxyAssertSupport.assertEquals(11L, sm.readLong());
   ProxyAssertSupport.assertEquals("this is an object", sm.readObject());
   ProxyAssertSupport.assertEquals((short) 12, sm.readShort());
   ProxyAssertSupport.assertEquals("this is a String", sm.readString());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:26,代码来源:StreamMessageTest.java

示例13: wrapMessage

import javax.jms.StreamMessage; //导入依赖的package包/类
/**
 * Wrap message
 *
 * @param message The message to be wrapped
 * @return The wrapped message
 */
Message wrapMessage(final Message message) {
   if (ActiveMQRAMessageConsumer.trace) {
      ActiveMQRALogger.LOGGER.trace("wrapMessage(" + message + ")");
   }

   if (message instanceof BytesMessage) {
      return new ActiveMQRABytesMessage((BytesMessage) message, session);
   } else if (message instanceof MapMessage) {
      return new ActiveMQRAMapMessage((MapMessage) message, session);
   } else if (message instanceof ObjectMessage) {
      return new ActiveMQRAObjectMessage((ObjectMessage) message, session);
   } else if (message instanceof StreamMessage) {
      return new ActiveMQRAStreamMessage((StreamMessage) message, session);
   } else if (message instanceof TextMessage) {
      return new ActiveMQRATextMessage((TextMessage) message, session);
   }
   return new ActiveMQRAMessage(message, session);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:25,代码来源:ActiveMQRAMessageConsumer.java

示例14: duplicateStreamMessage

import javax.jms.StreamMessage; //导入依赖的package包/类
private static AbstractMessage duplicateStreamMessage( StreamMessage srcMessage ) throws JMSException
{
    StreamMessageImpl copy = new StreamMessageImpl();
    copyHeaders(srcMessage,copy);
    
    srcMessage.reset();
    try
    {
        while (true)
            copy.writeObject(srcMessage.readObject());
    }
    catch (MessageEOFException e)
    {
        // Complete
    }
    
    return copy;
}
 
开发者ID:timewalker74,项目名称:ffmq,代码行数:19,代码来源:MessageTools.java

示例15: getBytes

import javax.jms.StreamMessage; //导入依赖的package包/类
private byte[] getBytes(Message receivedMessage, int testBytesLength) throws JMSException
{
    byte[] byteResults = new byte[testBytesLength];

    if (receivedMessage instanceof BytesMessage)
    {
        assertEquals(testBytesLength, ((BytesMessage) receivedMessage).readBytes(byteResults));
    }
    else if (receivedMessage instanceof StreamMessage)
    {
        assertEquals(testBytesLength, ((StreamMessage) receivedMessage).readBytes(byteResults));
    }
    else if (receivedMessage instanceof MapMessage)
    {
        byteResults = ((MapMessage) receivedMessage).getBytes(BYTE_TEST);
        assertEquals(testBytesLength, byteResults.length);
    }
    else if (receivedMessage instanceof TextMessage)
    {
        byteResults = ((TextMessage) receivedMessage).getText().getBytes();
        assertEquals(testBytesLength, byteResults.length);
    }


    return byteResults;
}
 
开发者ID:wso2,项目名称:andes,代码行数:27,代码来源:MessageToStringTest.java


注:本文中的javax.jms.StreamMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。