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


Java BytesMessage.writeBytes方法代碼示例

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


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

import javax.jms.BytesMessage; //導入方法依賴的package包/類
public void send(byte[] message) {
    if (session == null) {
        logger.warning("Session is null - sending monitoring message aborted");
        return;
    }
    if (queue == null) {
        logger.warning("Queue is null - sending monitoring message aborted");
        return;
    }
    if (producer == null) {
        logger.warning("Producer is null - sending monitoring message aborted");
        return;
    }
    try {
        BytesMessage bytesMessage = session.createBytesMessage();
        bytesMessage.writeBytes(message);
        producer.send(bytesMessage);
    } catch (JMSException ex) {
        logger.log(Level.SEVERE, "Message sending error", ex);
    }
    //logger.info("Sent monitoring message");
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:23,代碼來源:MonitoringMessageSender.java

示例3: toMessage

import javax.jms.BytesMessage; //導入方法依賴的package包/類
/**
 * 
 * @param session
 * @param frame
 * @return
 * @throws JMSException
 */
public Message toMessage(Session session, Frame frame) throws JMSException {
	// FIXME buffer pool
	final Message msg;
	if (frame.contains(CONTENT_LENGTH)) {
		final ByteBuffer buf = frame.body().get();
		byte[] bytes = new byte[buf.remaining()];
		buf.get(bytes);
		final BytesMessage bm = session.createBytesMessage();
		bm.writeBytes(bytes);
		msg = bm;
	} else {
		msg = session.createTextMessage(UTF_8.decode(frame.body().get()).toString());
	}
	copyHeaders(session, frame, msg);
	return msg;
}
 
開發者ID:dansiviter,項目名稱:cito,代碼行數:24,代碼來源:Factory.java

示例4: publish

import javax.jms.BytesMessage; //導入方法依賴的package包/類
@Override
protected <T> boolean publish(Channel<T> channel, T data) {
  MessageProducer producer = getProducerForChannel(channel);
  try {
    byte[] serializedObject = getSerializer().serialize(data);

    BytesMessage bm = messageCreationSession.createBytesMessage();
    bm.writeBytes(serializedObject);

    producer.send(bm);
  } catch (JMSException e) {
    logger.error("JMS message publishing failed", e);
    return false;
  }

  return true;
}
 
開發者ID:Telecooperation,項目名稱:assistance-platform-server,代碼行數:18,代碼來源:JmsMessagingService.java

示例5: invoke

import javax.jms.BytesMessage; //導入方法依賴的package包/類
/**
 * Called when new data arrives to the sink, and forwards it to RMQ.
 *
 * @param value
 *            The incoming data
 */
@Override
public void invoke(IN value) {
    try {
        byte[] bytes = serializationSchema.serialize(value);
        BytesMessage message = session.createBytesMessage();
        message.writeBytes(bytes);
        producer.send(message);
    } catch (JMSException e) {
        if (logFailuresOnly) {
            LOG.error("Failed to send message to ActiveMQ", e);
        } else {
            throw new RuntimeException("Failed to send message to ActiveMQ", e);
        }
    }
}
 
開發者ID:apache,項目名稱:bahir-flink,代碼行數:22,代碼來源:AMQSink.java

示例6: doTestSendJMSReceiveMQTT

import javax.jms.BytesMessage; //導入方法依賴的package包/類
public void doTestSendJMSReceiveMQTT(String destinationName) throws Exception {
   final MQTTClientProvider provider = getMQTTClientProvider();
   initializeConnection(provider);
   provider.subscribe("foo/+", AT_MOST_ONCE);

   Connection connection = cf.createConnection();
   connection.start();

   Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   javax.jms.Topic topic = s.createTopic(destinationName);
   MessageProducer producer = s.createProducer(topic);

   // send retained message from JMS
   final byte[] bytes = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
   BytesMessage bytesMessage = s.createBytesMessage();
   bytesMessage.writeBytes(bytes);
   producer.send(bytesMessage);

   byte[] message = provider.receive(10000);
   assertNotNull("Should get retained message", message);
   assertArrayEquals(bytes, message);

   provider.disconnect();
   connection.close();
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:MQTTTest.java

示例7: testLargePayload

import javax.jms.BytesMessage; //導入方法依賴的package包/類
public void testLargePayload() throws Exception {
   Queue dest = session.createQueue("TEST");
   MessageProducer prod = null;
   try {
      prod = session.createProducer(dest);
      BytesMessage msg = session.createBytesMessage();
      msg.writeBytes(messageData);
      prod.send(msg);
   } finally {
      prod.close();
   }
   MessageConsumer cons = null;
   try {
      cons = session.createConsumer(dest);
      assertNotNull(cons.receive(30000L));
   } finally {
      cons.close();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:20,代碼來源:NIOSSLWindowSizeTest.java

示例8: prepareMessage

import javax.jms.BytesMessage; //導入方法依賴的package包/類
@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();
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:19,代碼來源:BytesMessageTest.java

示例9: publishOrder

import javax.jms.BytesMessage; //導入方法依賴的package包/類
/**
 * @param order - Order to be placed
 * @param ttl - Time to live. Set to 0 for indefinite
 * @param deliveryMode - Set to 1 for non-persistent. Default 0
 */
public void publishOrder(Order order, MessageProducer mp) {
	BytesMessage orderMessage;
	try {
		Session session = this.createSession();

		// Create a new ByteMessage
		orderMessage = session.createBytesMessage();

		// Serialize the tick content into the message
		orderMessage.writeBytes(order.serialize());
		orderMessage.setStringProperty("Symbol", order.getSymbol());

		mp.send(orderMessage);
		this.closeSession(session);
	} catch (JMSException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
開發者ID:sgrotz,項目名稱:myopentrader,代碼行數:26,代碼來源:ActiveMQFactory.java

示例10: testMessageExpiredAdvisory

import javax.jms.BytesMessage; //導入方法依賴的package包/類
public void testMessageExpiredAdvisory() throws Exception {
   Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue queue = s.createQueue(getClass().getName());
   MessageConsumer consumer = s.createConsumer(queue);
   assertNotNull(consumer);

   Topic advisoryTopic = AdvisorySupport.getExpiredMessageTopic((ActiveMQDestination) queue);
   MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
   //start throwing messages at the consumer
   MessageProducer producer = s.createProducer(queue);
   producer.setTimeToLive(1);
   for (int i = 0; i < MESSAGE_COUNT; i++) {
      BytesMessage m = s.createBytesMessage();
      m.writeBytes(new byte[1024]);
      producer.send(m);
   }

   Message msg = advisoryConsumer.receive(2000);
   assertNotNull(msg);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:21,代碼來源:AdvisoryTests.java

示例11: send

import javax.jms.BytesMessage; //導入方法依賴的package包/類
@Override
public JMSProducer send(Destination destination, byte[] body) {
    try {
        BytesMessage message = session.createBytesMessage();
        message.writeBytes(body);
        doSend(destination, message);
    } catch (JMSException jmse) {
        throw JMSExceptionSupport.createRuntimeException(jmse);
    }

    return this;
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:13,代碼來源:JmsPoolJMSProducer.java

示例12: send

import javax.jms.BytesMessage; //導入方法依賴的package包/類
@Override
public JMSProducer send(Destination destination, byte[] body) {
    try {
        BytesMessage message = context.createBytesMessage();
        message.writeBytes(body);
        doSend(destination, message);
    } catch (JMSException jmse) {
        throw Utils.convertToRuntimeException(jmse);
    }
    return this;
}
 
開發者ID:ops4j,項目名稱:org.ops4j.pax.transx,代碼行數:12,代碼來源:JMSProducerImpl.java

示例13: mapToBytesMessage

import javax.jms.BytesMessage; //導入方法依賴的package包/類
/**
 * Map the given object to a {@link BytesMessage}.
 * @param object the object to be mapped
 * @param session current JMS session
 * @param objectMapper the mapper to use
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @throws IOException in case of I/O errors
 * @see Session#createBytesMessage
 */
protected BytesMessage mapToBytesMessage(Object object, Session session, ObjectMapper objectMapper)
        throws JMSException, IOException {

    ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
    OutputStreamWriter writer = new OutputStreamWriter(bos, this.encoding);
    objectMapper.writeValue(writer, object);

    BytesMessage message = session.createBytesMessage();
    message.writeBytes(bos.toByteArray());
    if (this.encodingPropertyName != null) {
        message.setStringProperty(this.encodingPropertyName, this.encoding);
    }
    return message;
}
 
開發者ID:kinglcc,項目名稱:spring-boot-jms,代碼行數:25,代碼來源:Jackson2JmsMessageConverter.java

示例14: mapToBytesMessage

import javax.jms.BytesMessage; //導入方法依賴的package包/類
/**
 * Map the given object to a {@link BytesMessage}.
 * @param object the object to be mapped
 * @param session current JMS session
 * @param objectMapper the mapper to use
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @throws IOException in case of I/O errors
 * @see Session#createBytesMessage
 */
protected BytesMessage mapToBytesMessage(Object object, Session session, ObjectMapper objectMapper)
		throws JMSException, IOException {

	ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
	OutputStreamWriter writer = new OutputStreamWriter(bos, this.encoding);
	objectMapper.writeValue(writer, object);

	BytesMessage message = session.createBytesMessage();
	message.writeBytes(bos.toByteArray());
	if (this.encodingPropertyName != null) {
		message.setStringProperty(this.encodingPropertyName, this.encoding);
	}
	return message;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:MappingJackson2MessageConverter.java

示例15: createMessageWithPayload

import javax.jms.BytesMessage; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected Message createMessageWithPayload(Session session, BytesMessageData messageData) throws JMSException {
    BytesMessage msg = session.createBytesMessage();
    msg.writeBytes(messageData.getData());
    return msg;
}
 
開發者ID:erik-wramner,項目名稱:JmsTools,代碼行數:10,代碼來源:BytesMessageProvider.java


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