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


Java StreamMessage.writeString方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: testSendJMSStreamMessage

import javax.jms.StreamMessage; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testSendJMSStreamMessage() 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);
    StreamMessage message = session.createStreamMessage();
    message.writeString(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 StreamMessage);
    StreamMessage stream = (StreamMessage) received;
    assertEquals(payload, stream.readString());
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:25,代码来源:JmsProduceMessageTypesTest.java

示例9: testSendJMSStreamMessage

import javax.jms.StreamMessage; //导入方法依赖的package包/类
@Ignore
@Test(timeout = 60000)
public void testSendJMSStreamMessage() throws Exception {
    connection = createStompConnection();
    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);
    StreamMessage message = session.createStreamMessage();
    message.writeString(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 StreamMessage);
    StreamMessage stream = (StreamMessage) received;
    assertEquals(payload, stream.readString());
}
 
开发者ID:fusesource,项目名称:hawtjms,代码行数:26,代码来源:JmsProduceMessageTypesTest.java

示例10: sendStreamMessageUsingCoreJms

import javax.jms.StreamMessage; //导入方法依赖的package包/类
private void sendStreamMessageUsingCoreJms(String queueName) throws Exception {
   Connection jmsConn = null;
   try {
      jmsConn = coreCf.createConnection();
      Session session = jmsConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      StreamMessage msg = session.createStreamMessage();
      msg.writeBoolean(true);
      msg.writeByte((byte) 2);
      msg.writeBytes(new byte[]{6, 7});
      msg.writeChar('b');
      msg.writeDouble(6.5);
      msg.writeFloat((float) 93.9);
      msg.writeInt(7657);
      msg.writeLong(239999L);
      msg.writeShort((short) 34222);
      msg.writeString("hello streammessage");

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

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

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:29,代码来源:GeneralInteropTest.java

示例11: testCompression

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

   Connection cconnection = null;
   Connection connection = null;
   try {
      ActiveMQConnectionFactory cfactory = new ActiveMQConnectionFactory("tcp://" + OWHOST + ":" + OWPORT + "");
      cconnection = cfactory.createConnection();
      cconnection.start();
      Session csession = cconnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Queue cQueue = csession.createQueue(queueName);
      MessageConsumer consumer = csession.createConsumer(cQueue);

      ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://" + OWHOST + ":" + OWPORT + "?jms.useCompression=true");
      connection = factory.createConnection();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Queue queue = session.createQueue(queueName);

      MessageProducer producer = session.createProducer(queue);
      producer.setDeliveryMode(DeliveryMode.PERSISTENT);

      //text
      TextMessage textMessage = session.createTextMessage();
      textMessage.setText(testString);
      TextMessage receivedMessage = sendAndReceive(textMessage, producer, consumer);

      String receivedText = receivedMessage.getText();
      assertEquals(testString, receivedText);

      //MapMessage
      MapMessage mapMessage = session.createMapMessage();
      mapMessage.setString(testProp, propValue);
      MapMessage receivedMapMessage = sendAndReceive(mapMessage, producer, consumer);
      String value = receivedMapMessage.getString(testProp);
      assertEquals(propValue, value);

      //Object
      ObjectMessage objMessage = session.createObjectMessage();
      objMessage.setObject(testString);
      ObjectMessage receivedObjMessage = sendAndReceive(objMessage, producer, consumer);
      String receivedObj = (String) receivedObjMessage.getObject();
      assertEquals(testString, receivedObj);

      //Stream
      StreamMessage streamMessage = session.createStreamMessage();
      streamMessage.writeString(testString);
      StreamMessage receivedStreamMessage = sendAndReceive(streamMessage, producer, consumer);
      String streamValue = receivedStreamMessage.readString();
      assertEquals(testString, streamValue);

      //byte
      BytesMessage byteMessage = session.createBytesMessage();
      byte[] bytes = testString.getBytes();
      byteMessage.writeBytes(bytes);

      BytesMessage receivedByteMessage = sendAndReceive(byteMessage, producer, consumer);
      long receivedBodylength = receivedByteMessage.getBodyLength();

      assertEquals("bodylength Correct", bytes.length, receivedBodylength);

      byte[] receivedBytes = new byte[(int) receivedBodylength];
      receivedByteMessage.readBytes(receivedBytes);

      String receivedString = new String(receivedBytes);
      assertEquals(testString, receivedString);

      //Message
      Message m = session.createMessage();
      sendAndReceive(m, producer, consumer);
   } finally {
      if (cconnection != null) {
         connection.close();
      }
      if (connection != null) {
         cconnection.close();
      }
   }

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:80,代码来源:SimpleOpenWireTest.java

示例12: testPersistedMessageType

import javax.jms.StreamMessage; //导入方法依赖的package包/类
@Test
public void testPersistedMessageType() throws Exception {
   Connection theConn = null;
   Connection theOtherConn = null;

   try {
      theConn = createConnection();
      theConn.start();

      // Send some persistent messages to a queue with no receivers
      Session sessSend = theConn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageProducer theProducer = sessSend.createProducer(queue1);
      theProducer.setDeliveryMode(DeliveryMode.PERSISTENT);

      Message m = sessSend.createMessage();
      m.setStringProperty("p1", "aardvark");

      BytesMessage bm = sessSend.createBytesMessage();
      bm.writeObject("aardvark");

      MapMessage mm = sessSend.createMapMessage();
      mm.setString("s1", "aardvark");

      ObjectMessage om = sessSend.createObjectMessage();
      om.setObject("aardvark");

      StreamMessage sm = sessSend.createStreamMessage();
      sm.writeString("aardvark");

      TextMessage tm = sessSend.createTextMessage("aardvark");

      theProducer.send(m);
      theProducer.send(bm);
      theProducer.send(mm);
      theProducer.send(om);
      theProducer.send(sm);
      theProducer.send(tm);

      theConn.close();

      theOtherConn = createConnection();
      theOtherConn.start();

      Session sessReceive = theOtherConn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageConsumer theConsumer = sessReceive.createConsumer(queue1);

      Message m2 = theConsumer.receive(1500);

      log.trace("m2 is " + m2);

      ProxyAssertSupport.assertNotNull(m2);

      ProxyAssertSupport.assertEquals("aardvark", m2.getStringProperty("p1"));

      BytesMessage bm2 = (BytesMessage) theConsumer.receive(1500);
      ProxyAssertSupport.assertEquals("aardvark", bm2.readUTF());

      MapMessage mm2 = (MapMessage) theConsumer.receive(1500);
      ProxyAssertSupport.assertEquals("aardvark", mm2.getString("s1"));

      ObjectMessage om2 = (ObjectMessage) theConsumer.receive(1500);
      ProxyAssertSupport.assertEquals("aardvark", (String) om2.getObject());

      StreamMessage sm2 = (StreamMessage) theConsumer.receive(1500);
      ProxyAssertSupport.assertEquals("aardvark", sm2.readString());

      TextMessage tm2 = (TextMessage) theConsumer.receive(1500);
      ProxyAssertSupport.assertEquals("aardvark", tm2.getText());
   } finally {
      if (theConn != null) {
         theConn.close();
      }
      if (theOtherConn != null) {
         theOtherConn.close();
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:80,代码来源:MessageConsumerTest.java

示例13: newStreamMessage

import javax.jms.StreamMessage; //导入方法依赖的package包/类
public static StreamMessage newStreamMessage(Session session, int size) throws JMSException
{
    StreamMessage message = session.createStreamMessage();
    message.writeString(createMessagePayload(size));
    return message;
}
 
开发者ID:wso2,项目名称:andes,代码行数:7,代码来源:TestMessageFactory.java

示例14: testSentStreamMessageIsReadOnly

import javax.jms.StreamMessage; //导入方法依赖的package包/类
@Test(timeout = 20000)
public void testSentStreamMessageIsReadOnly() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        testPeer.expectBegin();
        testPeer.expectSenderAttach();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("myQueue");
        MessageProducer producer = session.createProducer(queue);

        String myString = "myString";

        // Prepare a StreamMessage to send to the test peer to send
        StreamMessage streamMessage = session.createStreamMessage();

        streamMessage.writeString(myString);

        // prepare a matcher for the test peer to use to receive and verify the message
        List<Object> list = new ArrayList<Object>();
        list.add(myString);

        MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true).withDurable(equalTo(true));
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        msgAnnotationsMatcher.withEntry(Symbol.valueOf(AmqpMessageSupport.JMS_MSG_TYPE), equalTo(AmqpMessageSupport.JMS_STREAM_MESSAGE));
        MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true);
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setHeadersMatcher(headersMatcher);
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
        messageMatcher.setPropertiesMatcher(propertiesMatcher);
        messageMatcher.setMessageContentMatcher(new EncodedAmqpSequenceMatcher(list));

        testPeer.expectTransfer(messageMatcher);
        testPeer.expectClose();

        producer.send(streamMessage);

        try {
            streamMessage.writeString(myString);
            fail("Message should not be writable after a send.");
        } catch (MessageNotWriteableException mnwe) {}

        connection.close();

        testPeer.waitForAllHandlersToComplete(3000);
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:48,代码来源:StreamMessageIntegrationTest.java

示例15: testNullValue

import javax.jms.StreamMessage; //导入方法依赖的package包/类
@Test
public void testNullValue() throws Exception {
   StreamMessage m = session.createStreamMessage();

   m.writeString(null);

   queueProd.send(m);

   conn.start();

   StreamMessage rm = (StreamMessage) queueCons.receive();

   ProxyAssertSupport.assertNull(rm.readString());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:15,代码来源:StreamMessageTest.java


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