spring中消息持久化

	public void sendFanoutMessage(Object message) {
		//生成唯一随机值给confirm方法确认是否是同一消息
		CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); 
		logger.debug("RabbitMQ开始发送消息{}:", message.toString());
		// convertAndSend方法时默认发的持久化的信息,进去源码可以看到第三个参数是Message对象,
		// 而实例化Message对象的时候需要提供MessageProperties类对象,在MessageProperties类型默认的为持久化消息,PERSISTENT=2
		fanoutRabbitTemplate.convertAndSend(fanoutRabbitTemplate.getExchange(), "", message, correlationId);
		logger.debug("RabbitMQ结束发送消息{}:", message.toString());
	}

猜你喜欢

转载自blog.csdn.net/ncuzengxiebo/article/details/80804295
今日推荐