本文整理匯總了Java中org.springframework.jms.core.JmsTemplate.send方法的典型用法代碼示例。如果您正苦於以下問題:Java JmsTemplate.send方法的具體用法?Java JmsTemplate.send怎麽用?Java JmsTemplate.send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.jms.core.JmsTemplate
的用法示例。
在下文中一共展示了JmsTemplate.send方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validateFailOnUnsupportedMessageTypeOverJNDI
import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
public void validateFailOnUnsupportedMessageTypeOverJNDI() throws Exception {
final String destinationName = "testQueue";
JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);
jmsTemplate.send(destinationName, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createObjectMessage();
}
});
JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
try {
consumer.consume(destinationName, new ConsumerCallback() {
@Override
public void accept(JMSResponse response) {
// noop
}
});
} finally {
((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
}
示例2: validateFailOnUnsupportedMessageType
import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
* At the moment the only two supported message types are TextMessage and
* BytesMessage which is sufficient for the type if JMS use cases NiFi is
* used. The may change to the point where all message types are supported
* at which point this test will no be longer required.
*/
@Test(expected = IllegalStateException.class)
public void validateFailOnUnsupportedMessageType() throws Exception {
final String destinationName = "testQueue";
JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);
jmsTemplate.send(destinationName, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createObjectMessage();
}
});
JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
try {
consumer.consume(destinationName, new ConsumerCallback() {
@Override
public void accept(JMSResponse response) {
// noop
}
});
} finally {
((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
}
示例3: sendMessageDelay
import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
* 延遲發送對象消息
* @param jmsTemplate
* @param destination
* @param objectMessage
* @param delay
*/
public static void sendMessageDelay(JmsTemplate jmsTemplate, Destination destination, final Serializable objectMessage, final long delay) {
jmsTemplate.send(destination, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
ObjectMessage om = session.createObjectMessage(objectMessage);
om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1 * 1000);
om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
return om;
}
});
}
示例4: send
import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
* 發送數據
* @param jmsTemplate
* @param queue
*/
public void send(JmsTemplate jmsTemplate,ActiveMQDestination queue){
for(int i=0;i<10;i++){
final int k=i;
//發送消息
jmsTemplate.send(queue, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("hello!this is number:"+k);
}
});
}
}
示例5: sendMessage
import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
* 發送文本消息
* @param jmsTemplate
* @param destination
* @param textMessage
*/
public static void sendMessage(JmsTemplate jmsTemplate, Destination destination, final String textMessage) {
jmsTemplate.send(destination, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage(textMessage);
}
});
}
示例6: validateConsumeWithCustomHeadersAndProperties
import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
@Test
public void validateConsumeWithCustomHeadersAndProperties() throws Exception {
final String destinationName = "testQueue";
JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);
jmsTemplate.send(destinationName, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
TextMessage message = session.createTextMessage("hello from the other side");
message.setStringProperty("foo", "foo");
message.setBooleanProperty("bar", false);
message.setJMSReplyTo(session.createQueue("fooQueue"));
return message;
}
});
JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
final AtomicBoolean callbackInvoked = new AtomicBoolean();
consumer.consume(destinationName, new ConsumerCallback() {
@Override
public void accept(JMSResponse response) {
callbackInvoked.set(true);
assertEquals("hello from the other side", new String(response.getMessageBody()));
assertEquals("fooQueue", response.getMessageHeaders().get(JmsHeaders.REPLY_TO));
assertEquals("foo", response.getMessageProperties().get("foo"));
assertEquals("false", response.getMessageProperties().get("bar"));
}
});
assertTrue(callbackInvoked.get());
((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
示例7: sendMessageDelay
import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
* 延遲發送對象消息
* @param jmsTemplate
* @param destination
* @param objectMessage
* @param delay
*/
public static void sendMessageDelay(JmsTemplate jmsTemplate, Destination destination, final Serializable objectMessage, final long delay) {
jmsTemplate.send(destination, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
ObjectMessage om = session.createObjectMessage(objectMessage);
om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1 * 1000);
om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
return om;
}
});
}
示例8: sendMessage
import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
* 發送文本消息
* @param jmsTemplate
* @param destination
* @param textMessage
*/
public static void sendMessage(JmsTemplate jmsTemplate, Destination destination, final String textMessage) {
jmsTemplate.send(destination, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage(textMessage);
}
});
}
示例9: validateConsumeWithCustomHeadersAndPropertiesOverJNDI
import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
@Test
public void validateConsumeWithCustomHeadersAndPropertiesOverJNDI() throws Exception {
final String destinationName = "testQueue";
JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);
jmsTemplate.send(destinationName, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
TextMessage message = session.createTextMessage("hello from the other side");
message.setStringProperty("foo", "foo");
message.setBooleanProperty("bar", false);
message.setJMSReplyTo(session.createQueue("fooQueue"));
return message;
}
});
JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
final AtomicBoolean callbackInvoked = new AtomicBoolean();
consumer.consume(destinationName, new ConsumerCallback() {
@Override
public void accept(JMSResponse response) {
callbackInvoked.set(true);
assertEquals("hello from the other side", new String(response.getMessageBody()));
assertEquals("fooQueue", response.getMessageHeaders().get(JmsHeaders.REPLY_TO));
assertEquals("foo", response.getMessageProperties().get("foo"));
assertEquals("false", response.getMessageProperties().get("bar"));
}
});
assertTrue(callbackInvoked.get());
((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
示例10: sendMessage
import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
* 發送對象消息
* @param jmsTemplate
* @param destination
* @param objectMessage
*/
public static void sendMessage(JmsTemplate jmsTemplate, Destination destination, final Serializable objectMessage) {
jmsTemplate.send(destination, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createObjectMessage(objectMessage);
}
});
}