package com.bocloud.ims.service.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.bocloud.common.model.Result;

/**
 * cmdb消息同步分发器。
 * 
 * @author weiwei
 *
 */
@Component("cmdbMessagePublisher")
public class CmdbMessagePublisher {
	private static Logger logger = LoggerFactory.getLogger(CmdbMessagePublisher.class);
	private static final String QUEUE = "cmdb.message.queue";
	@Autowired
	private AmqpTemplate amqpTemplate;

	public Result send(Object message) {
		try {
			this.amqpTemplate.convertAndSend(QUEUE, JSONObject.parseObject(JSONObject.toJSONString(message)));
			return new Result(true, "success");
		} catch (AmqpException e) {
			logger.error("Send cmdb message Error{}", e);
			return new Result(false, "发送失败！");
		}
	}
}
