本文整理汇总了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);
}
}
示例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");
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}