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