本文整理匯總了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;
}