当前位置: 首页>>代码示例>>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;未经允许,请勿转载。