本文整理汇总了Java中javax.jms.BytesMessage.setStringProperty方法的典型用法代码示例。如果您正苦于以下问题:Java BytesMessage.setStringProperty方法的具体用法?Java BytesMessage.setStringProperty怎么用?Java BytesMessage.setStringProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jms.BytesMessage
的用法示例。
在下文中一共展示了BytesMessage.setStringProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: publishTick
import javax.jms.BytesMessage; //导入方法依赖的package包/类
/**
* @param tick
* @param ttl
* @param persistent
*/
public void publishTick(Tick tick, MessageProducer mp) {
BytesMessage tickMessage;
try {
Session session = this.createSession();
// Create a new ByteMessage
tickMessage = session.createBytesMessage();
// Serialize the tick content into the message
tickMessage.writeBytes(tick.serialize());
tickMessage.setStringProperty("Symbol", tick.getSymbol());
tickMessage.setStringProperty("Currency", tick.getCurrency());
mp.send(tickMessage);
this.closeSession(session);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例2: publishTicks
import javax.jms.BytesMessage; //导入方法依赖的package包/类
/**
*
* @param tick
* @param ttl
* @param persistent
*/
public void publishTicks(Tick[] tick, MessageProducer mp) {
BytesMessage tickMessage;
try {
Session session = this.createSession();
for (int i = 0; i < tick.length; i++ ) {
// Create a new ByteMessage
tickMessage = session.createBytesMessage();
// Serialize the tick content into the message
tickMessage.writeBytes(tick[i].serialize());
tickMessage.setStringProperty("Symbol", tick[i].getSymbol());
tickMessage.setStringProperty("Currency", tick[i].getCurrency());
mp.send(tickMessage);
}
this.closeSession(session);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例3: publishTickSize
import javax.jms.BytesMessage; //导入方法依赖的package包/类
/**
* @param tickSize
* @param ttl
* @param persistent
*/
public void publishTickSize(TickSize tickSize, MessageProducer mp) {
BytesMessage tickMessage;
try {
Session session = this.createSession();
// Create a new ByteMessage
tickMessage = session.createBytesMessage();
// Serialize the tick content into the message
tickMessage.writeBytes(tickSize.serialize());
tickMessage.setStringProperty("Symbol", tickSize.getSymbol());
mp.send(tickMessage);
this.closeSession(session);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例4: 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();
}
}
示例5: publishSimulationRequest
import javax.jms.BytesMessage; //导入方法依赖的package包/类
/**
* Publish a simulation request
*
* @param sr
* @param ttl
* @param persistent
*/
public void publishSimulationRequest(SimulationRequest sr, MessageProducer mp) {
BytesMessage simulationMessage;
try {
Session session = this.createSession();
// Create a new ByteMessage
simulationMessage = session.createBytesMessage();
// Serialize the simulation request content into the message
simulationMessage.writeBytes(sr.serialize());
simulationMessage.setStringProperty("Symbol", sr.getSymbol());
simulationMessage.setStringProperty("LoadValues", String.valueOf(sr.getLoadValues()));
simulationMessage.setStringProperty("StartDate", String.valueOf(sr.getStartDate()));
simulationMessage.setStringProperty("EndDate", String.valueOf(sr.getEndDate()));
mp.send(simulationMessage);
this.closeSession(session);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例6: testSendContentType
import javax.jms.BytesMessage; //导入方法依赖的package包/类
@Test
public void testSendContentType() throws Exception {
conn.connect(defUser, defPass);
subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
MessageProducer producer = session.createProducer(queue);
BytesMessage message = session.createBytesMessage();
message.setStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_CONTENT_TYPE.toString(), "text/plain");
message.writeBytes("Hello World".getBytes(StandardCharsets.UTF_8));
producer.send(message);
ClientStompFrame frame = conn.receiveFrame();
Assert.assertNotNull(frame);
Assert.assertEquals("text/plain", frame.getHeader(Stomp.Headers.CONTENT_TYPE));
conn.disconnect();
}
示例7: bytesMessage
import javax.jms.BytesMessage; //导入方法依赖的package包/类
@Test
public void bytesMessage() throws Exception {
context = cf.createContext();
try {
JMSProducer producer = context.createProducer();
BytesMessage bMsg = context.createBytesMessage();
bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
bMsg.writeByte((byte) 1);
bMsg.writeInt(22);
CountDownLatch latch = new CountDownLatch(1);
SimpleCompletionListener listener = new SimpleCompletionListener(latch);
producer.setAsync(listener);
producer.send(queue1, bMsg);
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertEquals(listener.message.readByte(), (byte) 1);
assertEquals(listener.message.readInt(), 22);
} finally {
context.close();
}
}
示例8: sendMessagesToBroker
import javax.jms.BytesMessage; //导入方法依赖的package包/类
protected void sendMessagesToBroker(Connection connection, int count, AtomicInteger sequence) throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(getQueueName());
MessageProducer producer = session.createProducer(queue);
byte[] buffer = new byte[MESSAGE_SIZE];
for (count = 0; count < MESSAGE_SIZE; count++) {
String s = String.valueOf(count % 10);
Character c = s.charAt(0);
int value = c.charValue();
buffer[count] = (byte) value;
}
LOG.debug("Sending {} messages to destination: {}", MESSAGE_COUNT, queue);
for (int i = 1; i <= MESSAGE_COUNT; i++) {
BytesMessage message = session.createBytesMessage();
message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
message.setStringProperty("JMSXGroupID", JMSX_GROUP_ID);
message.setIntProperty("JMSXGroupSeq", sequence.incrementAndGet());
message.writeBytes(buffer);
producer.send(message);
}
session.close();
}
示例9: 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;
}
示例10: 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;
}
示例11: newMessage
import javax.jms.BytesMessage; //导入方法依赖的package包/类
Message newMessage(final String body, final String deviceId, final String token) throws JMSException {
final BytesMessage message = session.createBytesMessage();
message.setStringProperty(MessageHelper.APP_PROPERTY_DEVICE_ID, deviceId);
message.setStringProperty(MessageHelper.APP_PROPERTY_REGISTRATION_ASSERTION, token);
message.writeUTF(body);
return message;
}
示例12: writeWindowId
import javax.jms.BytesMessage; //导入方法依赖的package包/类
private void writeWindowId(String appId, int operatorId, long windowId) throws JMSException
{
BytesMessage message = getBase().getSession().createBytesMessage();
message.setStringProperty(APP_OPERATOR_ID, appId + "_" + operatorId);
message.writeLong(windowId);
producer.send(message);
logger.debug("Message with windowId {} sent", windowId);
}
示例13: toMessage
import javax.jms.BytesMessage; //导入方法依赖的package包/类
@Override
public Message toMessage(Object obj, Session session) throws JMSException,
MessageConversionException {
logger.debug("Method : toMessage");
if (!(obj instanceof MessageBeanImpl)) {
throw new MessageConversionException("Obj is not MessageBeanImpl.");
}
/* Jms字节类型消息 */
BytesMessage bytesMessage = session.createBytesMessage();
MessageBeanImpl messageBean = (MessageBeanImpl) obj;
bytesMessage.setStringProperty("MessageType",
messageBean.getMessageType());
bytesMessage.setStringProperty("MessageAckNo",
messageBean.getMessageAckNo());
bytesMessage.setStringProperty("MessageNo", messageBean.getMessageNo());
bytesMessage.setLongProperty("MessageDate",
messageBean.getMessageDate());
bytesMessage.writeBytes(messageBean.getMessageContent());
logger.debug("Convert Success, The Send Message No is "
+ messageBean.getMessageNo());
return bytesMessage;
}
示例14: testSubscribeWithMessageSentWithProperties
import javax.jms.BytesMessage; //导入方法依赖的package包/类
@Test
public void testSubscribeWithMessageSentWithProperties() throws Exception {
conn.connect(defUser, defPass);
subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO);
MessageProducer producer = session.createProducer(queue);
BytesMessage message = session.createBytesMessage();
message.setStringProperty("S", "value");
message.setBooleanProperty("n", false);
message.setByteProperty("byte", (byte) 9);
message.setDoubleProperty("d", 2.0);
message.setFloatProperty("f", (float) 6.0);
message.setIntProperty("i", 10);
message.setLongProperty("l", 121);
message.setShortProperty("s", (short) 12);
message.writeBytes("Hello World".getBytes(StandardCharsets.UTF_8));
producer.send(message);
ClientStompFrame frame = conn.receiveFrame(10000);
Assert.assertNotNull(frame);
Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
Assert.assertEquals("value", frame.getHeader("S"));
Assert.assertEquals("false", frame.getHeader("n"));
Assert.assertEquals("9", frame.getHeader("byte"));
Assert.assertEquals("2.0", frame.getHeader("d"));
Assert.assertEquals("6.0", frame.getHeader("f"));
Assert.assertEquals("10", frame.getHeader("i"));
Assert.assertEquals("121", frame.getHeader("l"));
Assert.assertEquals("12", frame.getHeader("s"));
Assert.assertEquals("Hello World", frame.getBody());
conn.disconnect();
}
示例15: testSubscribeWithMessageSentWithProperties
import javax.jms.BytesMessage; //导入方法依赖的package包/类
@Test
public void testSubscribeWithMessageSentWithProperties() throws Exception {
conn.connect(defUser, defPass);
subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
MessageProducer producer = session.createProducer(queue);
BytesMessage message = session.createBytesMessage();
message.setStringProperty("S", "value");
message.setBooleanProperty("n", false);
message.setByteProperty("byte", (byte) 9);
message.setDoubleProperty("d", 2.0);
message.setFloatProperty("f", (float) 6.0);
message.setIntProperty("i", 10);
message.setLongProperty("l", 121);
message.setShortProperty("s", (short) 12);
message.writeBytes("Hello World".getBytes(StandardCharsets.UTF_8));
producer.send(message);
ClientStompFrame frame = conn.receiveFrame();
Assert.assertNotNull(frame);
Assert.assertTrue(frame.getHeader("S") != null);
Assert.assertTrue(frame.getHeader("n") != null);
Assert.assertTrue(frame.getHeader("byte") != null);
Assert.assertTrue(frame.getHeader("d") != null);
Assert.assertTrue(frame.getHeader("f") != null);
Assert.assertTrue(frame.getHeader("i") != null);
Assert.assertTrue(frame.getHeader("l") != null);
Assert.assertTrue(frame.getHeader("s") != null);
Assert.assertEquals("Hello World", frame.getBody());
conn.disconnect();
}