码迷,mamicode.com
首页 > 编程语言 > 详细

spring rabbitTemplate消息DeliveryMode设置

时间:2014-09-20 10:05:37      阅读:1767      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   os   java   ar   文件   2014   sp   

在用spring和rabbitmq整合 对message的DeliveryMode的设置有两种方式

一,在发送消息的时候设置DeliveryMode

1,生产者调用rabbimqTemplate发送消息的时候,调用接口

	public Message sendAndReceive(final String exchange, final String routingKey, final Message message)
			throws AmqpException {
		return this.doSendAndReceive(exchange, routingKey, message);
	}

2,对其中的参数Message设置MessageProperties属性

public class MessageProperties implements Serializable {

	static final String DEFAULT_CONTENT_TYPE = CONTENT_TYPE_BYTES;

	static final MessageDeliveryMode DEFAULT_DELIVERY_MODE = MessageDeliveryMode.PERSISTENT;//默认消息是持久化
          ......略
}

二,在spring和rabbitmq的配置文件中配置自定义MessageConverter

 */
public interface MessageConverter {

	/**
	 * Convert a Java object to a Message.
	 * @param object the object to convert
	 * @param messageProperties The message properties.
	 * @return the Message
	 * @throws MessageConversionException in case of conversion failure
	 */
	Message toMessage(Object object, MessageProperties messageProperties) throws MessageConversionException;

	/**
	 * Convert from a Message to a Java object.
	 * @param message the message to convert
	 * @return the converted Java object
	 * @throws MessageConversionException in case of conversion failure
	 */
	Object fromMessage(Message message) throws MessageConversionException;

}


配置其默认实现

<bean class="org.springframework.amqp.rabbit.core.RabbitTemplate">
    <property name="connectionFactory" ref="rabbitConnectionFactory"/>
    <property name="messageConverter" ref="">
</bean>

 <bean class="org.springframework.amqp.support.converter.SimpleMessageConverter">
  </bean

 

参考:http://docs.spring.io/spring-amqp/reference/html/amqp.html


spring rabbitTemplate消息DeliveryMode设置

标签:blog   http   io   os   java   ar   文件   2014   sp   

原文地址:http://blog.csdn.net/joeyon1985/article/details/39429117

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!