The JmsTemplate
contains many convenience methods to send a message. There are send methods that specify the destination using a javax.jms.Destination
object and those that specify the destination using a string for use in a JNDI lookup. The send method that takes no destination argument uses the default destination. Here is an example that sends a message to a queue using the 1.0.2 implementation.
import javax.jms.ConnectionFactory; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.Queue; import javax.jms.Session; import org.springframework.jms.core.MessageCreator; import org.springframework.jms.core.JmsTemplate; public class JmsQueueSender { private JmsTemplate jmsTemplate; private Queue queue; public void setConnectionFactory(ConnectionFactory cf) { this.jmsTemplate = new JmsTemplate(cf, false); } public void setQueue(Queue queue) { this.queue = queue; } public void simpleSend() { this.jmsTemplate.send(this.queue, new MessageCreator() { public Message createMessage(Session session) throws JMSException { return session.createTextMessage("hello queue world"); } }); } }
This example uses the MessageCreator
callback to create a text message from the supplied Session
object and the JmsTemplate
is constructed by passing a reference to a ConnectionFactory
and a boolean specifying the messaging domain. A zero argument constructor and connectionFactory / queue bean properties are provided and can be used for constructing the instance (using a BeanFactory or plain Java code). Alternatively, consider deriving from Spring's JmsGatewaySupport
convenience base class, which provides pre-built bean properties for JMS configuration.
The method send(String destinationName, MessageCreator creator)
lets you send to a message using the string name of the destination. If these names are registered in JNDI, you should set the destinationResolver property of the template to an instance of JndiDestinationResolver
.
If you created the JmsTemplate
and specified a default destination, the send(MessageCreator c)
sends a message to that destination.
From:http://docs.spring.io/spring/docs/3.0.0.RC2/reference/html/ch21s03.html
相关推荐
send message函数详解
C# Send Message
This is the sample about user send message to android device by GCM(google cloud message)
wechat send message 这是一个可以自动发送微信消息以及朋友圈的小工具。这个小工具其实是一个用Uiautomator在Android Studio下写的微信自动测试。 写这个工具的初衷是为了收集微信通信数据,没有在google到相关的...
Message send by mapi with ADO
使用cxf webservice时容易出现的异常
ssh auto send keyboard message projectssh auto send keyboard message project
• Send messages via JMS and AMQP by using ActiveMQ and RabbitMQ. • Use dynamic languages like Groovy, Ruby, and Bean Shell. • Use Groovy with Spring. • Use the new Spring Boot and Spring XD ...
Other highlights include learning how to build the Java DAO implementation layer by leveraging the Data Access Object design pattern, securing your applications against malicious intruders, and ...
send message text java class
Other highlights include learning how to build the Java DAO implementation layer by leveraging the Data Access Object design pattern, securing your applications against malicious intruders, and ...
spring-framework-4.3.6.RELEASE - 解包大小为 44.9 MB ## Spring Framework The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications ...
spring.application.name=SEND-MAIL #授权密码 spring.mail.password=password #邮箱服务器默认端口 spring.mail.port=25 #协议 spring.mail.protocol=smtp #邮箱账号名 spring.mail.username=Email_Name #Spring...
两个进程间postmessage例子,希望会大家有用
Send Message[message] by http. 正如你所看到的,在执行MessageSender的send方法前先执行了LogBeforeAdvice的方法!在这个例子中,记录日志的代码并没有横切到我们的业务代码中,LogBeforeAdvice和...
Keil5 for stm32 的发短信工程,比较简单实用 可以用作智能控制方面的应用
Message消息的两种发送方式样例send和post.rar.rar
send string between inter process
http://blog.csdn.net/lindonglian/article/details/43315681