當前位置: 首頁>>代碼示例>>Java>>正文


Java BytesMessage.setObjectProperty方法代碼示例

本文整理匯總了Java中javax.jms.BytesMessage.setObjectProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java BytesMessage.setObjectProperty方法的具體用法?Java BytesMessage.setObjectProperty怎麽用?Java BytesMessage.setObjectProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.jms.BytesMessage的用法示例。


在下文中一共展示了BytesMessage.setObjectProperty方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doSendBinaryMessage

import javax.jms.BytesMessage; //導入方法依賴的package包/類
private void doSendBinaryMessage( final Session session, final Destination destination,
                                  final byte[] bytes,
                                  final Map<String, ?> properties ) throws JMSException {

    try {
        BytesMessage message = session.createBytesMessage();
        message.writeBytes(bytes);
        if (properties != null) {
            // Note: Setting any properties (including JMS fields) using
            // setObjectProperty might not be supported by all providers
            // Tested with: ActiveMQ
            for (final Entry<String, ?> property : properties.entrySet()) {
                message.setObjectProperty(property.getKey(), property.getValue());
            }
        }
        final MessageProducer producer = session.createProducer(destination);
        producer.send(message);
    } finally {
        releaseSession(false);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:22,代碼來源:JmsClient.java

示例2: createMessageWithBinaryData

import javax.jms.BytesMessage; //導入方法依賴的package包/類
/**
 * Creates a blob message that can be send via a producer that contains the given BasicMessage's JSON encoded data
 * along with binary data.
 *
 * @param context the context whose session is used to create the message
 * @param basicMessage contains the data that will be JSON-encoded and encapsulated in the created message, with
 *            optional headers included
 * @param inputStream binary data that will be sent with the message
 * @param headers headers for the Message that will override same-named headers in the basic message
 * @return the message that can be produced
 * @throws JMSException any error
 * @throws NullPointerException if the context is null or the context's session is null
 */
protected Message createMessageWithBinaryData(ConnectionContext context, BasicMessage basicMessage,
        InputStream inputStream, Map<String, String> headers) throws JMSException {
    if (context == null) {
        throw new IllegalArgumentException("The context is null");
    }
    if (basicMessage == null) {
        throw new IllegalArgumentException("The message is null");
    }
    if (inputStream == null) {
        throw new IllegalArgumentException("The binary data is null");
    }

    Session session = context.getSession();
    if (session == null) {
        throw new IllegalArgumentException("The context had a null session");
    }

    // we are going to use BinaryData which allows us to prefix the binary data with the JSON message
    BinaryData messagePlusBinaryData = new BinaryData(basicMessage.toJSON().getBytes(), inputStream);

    BytesMessage msg = session.createBytesMessage();
    msg.setObjectProperty("JMS_AMQ_InputStream", messagePlusBinaryData);

    setHeaders(basicMessage, headers, msg);

    log.infof("Created binary message [%s]", msg);

    return msg;
}
 
開發者ID:hawkular,項目名稱:hawkular-bus,代碼行數:43,代碼來源:MessageProcessor.java

示例3: createMessageWithBinaryData

import javax.jms.BytesMessage; //導入方法依賴的package包/類
/**
 * Creates a blob message that can be send via a producer that contains the given BasicMessage's JSON encoded data
 * along with binary data.
 *
 * @param context the context whose session is used to create the message
 * @param basicMessage contains the data that will be JSON-encoded and encapsulated in the created message, with
 *            optional headers included
 * @param inputStream binary data that will be sent with the message
 * @param headers headers for the Message that will override same-named headers in the basic message
 * @return the message that can be produced
 * @throws JMSException any error
 * @throws NullPointerException if the context is null or the context's session is null
 */
protected Message createMessageWithBinaryData(ConnectionContext context, BasicMessage basicMessage,
        InputStream inputStream, Map<String, String> headers) throws JMSException {
    if (context == null) {
        throw new IllegalArgumentException("The context is null");
    }
    if (basicMessage == null) {
        throw new IllegalArgumentException("The message is null");
    }
    if (inputStream == null) {
        throw new IllegalArgumentException("The binary data is null");
    }

    Session session = context.getSession();
    if (session == null) {
        throw new IllegalArgumentException("The context had a null session");
    }

    // we are going to use BinaryData which allows us to prefix the binary data with the JSON message
    BinaryData messagePlusBinaryData = new BinaryData(basicMessage.toJSON().getBytes(), inputStream);

    BytesMessage msg = session.createBytesMessage();
    msg.setObjectProperty("JMS_AMQ_InputStream", messagePlusBinaryData);

    setHeaders(basicMessage, headers, msg);

    log.debugf("Created binary message [%s]", msg);

    return msg;
}
 
開發者ID:hawkular,項目名稱:hawkular-commons,代碼行數:43,代碼來源:MessageProcessor.java

示例4: testResendWithLargeMessage

import javax.jms.BytesMessage; //導入方法依賴的package包/類
@Test
public void testResendWithLargeMessage() throws Exception {
   conn = cf.createConnection();
   conn.start();

   Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
   ArrayList<Message> msgs = new ArrayList<>();

   for (int i = 0; i < 10; i++) {
      BytesMessage bm = sess.createBytesMessage();
      bm.setObjectProperty(ActiveMQJMSConstants.JMS_ACTIVEMQ_INPUT_STREAM, ActiveMQTestBase.createFakeLargeStream(2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE));
      msgs.add(bm);

      MapMessage mm = sess.createMapMessage();
      mm.setBoolean("boolean", true);
      mm.setByte("byte", (byte) 3);
      mm.setBytes("bytes", new byte[]{(byte) 3, (byte) 4, (byte) 5});
      mm.setChar("char", (char) 6);
      mm.setDouble("double", 7.0);
      mm.setFloat("float", 8.0f);
      mm.setInt("int", 9);
      mm.setLong("long", 10L);
      mm.setObject("object", new String("this is an object"));
      mm.setShort("short", (short) 11);
      mm.setString("string", "this is a string");

      msgs.add(mm);
      msgs.add(sess.createTextMessage("hello" + i));
      msgs.add(sess.createObjectMessage(new SomeSerializable("hello" + i)));
   }

   internalTestResend(msgs, sess);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:34,代碼來源:ReSendMessageTest.java

示例5: testSimpleLargeMessage2

import javax.jms.BytesMessage; //導入方法依賴的package包/類
@Test
public void testSimpleLargeMessage2() throws Exception {
   conn = cf.createConnection();

   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   MessageProducer prod = session.createProducer(queue1);

   BytesMessage m = session.createBytesMessage();

   m.setObjectProperty("JMS_AMQ_InputStream", ActiveMQTestBase.createFakeLargeStream(10));

   prod.send(m);

   conn.close();

   conn = cf.createConnection();

   session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   MessageConsumer cons = session.createConsumer(queue1);

   conn.start();

   BytesMessage rm = (BytesMessage) cons.receive(10000);

   byte[] data = new byte[1024];

   System.out.println("Message = " + rm);

   int numberOfBytes = rm.readBytes(data);
   Assert.assertEquals(10, numberOfBytes);
   for (int j = 0; j < numberOfBytes; j++) {
      Assert.assertEquals(ActiveMQTestBase.getSamplebyte(j), data[j]);
   }

   Assert.assertNotNull(rm);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:39,代碼來源:JMSLargeMessageTest.java

示例6: testSimpleLargeMessage

import javax.jms.BytesMessage; //導入方法依賴的package包/類
@Test
public void testSimpleLargeMessage() throws Exception {

   conn = cf.createConnection();

   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   MessageProducer prod = session.createProducer(queue1);

   BytesMessage m = session.createBytesMessage();

   m.setObjectProperty("JMS_AMQ_InputStream", ActiveMQTestBase.createFakeLargeStream(1024 * 1024));

   prod.send(m);

   conn.close();

   conn = cf.createConnection();

   session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   MessageConsumer cons = session.createConsumer(queue1);

   conn.start();

   BytesMessage rm = (BytesMessage) cons.receive(10000);

   byte[] data = new byte[1024];

   System.out.println("Message = " + rm);

   for (int i = 0; i < 1024 * 1024; i += 1024) {
      int numberOfBytes = rm.readBytes(data);
      Assert.assertEquals(1024, numberOfBytes);
      for (int j = 0; j < 1024; j++) {
         Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i + j), data[j]);
      }
   }

   Assert.assertNotNull(rm);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:42,代碼來源:JMSLargeMessageTest.java

示例7: testWaitOnOutputStream

import javax.jms.BytesMessage; //導入方法依賴的package包/類
@Test
public void testWaitOnOutputStream() throws Exception {
   int msgSize = 1024 * 1024;

   conn = cf.createConnection();

   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   MessageProducer prod = session.createProducer(queue1);

   BytesMessage m = session.createBytesMessage();

   m.setObjectProperty("JMS_AMQ_InputStream", ActiveMQTestBase.createFakeLargeStream(msgSize));

   prod.send(m);

   conn.close();

   conn = cf.createConnection();

   session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   MessageConsumer cons = session.createConsumer(queue1);

   conn.start();

   BytesMessage rm = (BytesMessage) cons.receive(10000);
   Assert.assertNotNull(rm);

   final AtomicLong numberOfBytes = new AtomicLong(0);

   final AtomicInteger numberOfErrors = new AtomicInteger(0);

   OutputStream out = new OutputStream() {

      int position = 0;

      @Override
      public void write(final int b) throws IOException {
         numberOfBytes.incrementAndGet();
         if (ActiveMQTestBase.getSamplebyte(position++) != b) {
            System.out.println("Wrong byte at position " + position);
            numberOfErrors.incrementAndGet();
         }
      }

   };

   try {
      rm.setObjectProperty("JMS_AMQ_InputStream", ActiveMQTestBase.createFakeLargeStream(100));
      Assert.fail("Exception expected!");
   } catch (MessageNotWriteableException expected) {
   }

   rm.setObjectProperty("JMS_AMQ_SaveStream", out);

   Assert.assertEquals(msgSize, numberOfBytes.get());

   Assert.assertEquals(0, numberOfErrors.get());

}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:62,代碼來源:JMSLargeMessageTest.java


注:本文中的javax.jms.BytesMessage.setObjectProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。