org.springframework.amqp.rabbit.support.CorrelationData Java Examples

The following examples show how to use org.springframework.amqp.rabbit.support.CorrelationData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicService.java    From lemon-rabbitmq with Apache License 2.0 6 votes vote down vote up
public void sendMessage(final String serviceName, final String serviceMethodName,final String correlationId, Object request) {
	logger.info("sendMessage [this.{}, serviceMethodName:{} serviceName:{} correlationId: {}]", this.getClass(), serviceMethodName, serviceName, correlationId);
	rabbitTemplate.setCorrelationKey(correlationId);
	rabbitTemplate.convertAndSend(routingkey, request, new MessagePostProcessor() {            
    	@Override
        public Message postProcessMessage(Message message) throws AmqpException {
            message.getMessageProperties().setAppId(appId);
            message.getMessageProperties().setTimestamp(new Date());
            message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
            message.getMessageProperties().setCorrelationId(correlationId.getBytes());
            message.getMessageProperties().setHeader("ServiceMethodName", serviceMethodName);
            message.getMessageProperties().setHeader("ServiceName", serviceName);
            return message;
        }
    }, new CorrelationData(correlationId));
}
 
Example #2
Source File: RabbitSender.java    From code with Apache License 2.0 5 votes vote down vote up
public void send(Object message, Map<String, Object> properties) throws Exception {
	MessageHeaders mhs = new MessageHeaders(properties);
	Message msg = MessageBuilder.createMessage(message, mhs);
	rabbitTemplate.setConfirmCallback(confirmCallback);
	rabbitTemplate.setReturnCallback(returnCallback);
	//id + 时间戳 全局唯一 
	CorrelationData correlationData = new CorrelationData("1234567890");
	rabbitTemplate.convertAndSend("exchange-1", "springboot.abc", msg, correlationData);
}
 
Example #3
Source File: MQConfirmCallback.java    From lemon-rabbitmq with Apache License 2.0 5 votes vote down vote up
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
    System.out.println("回调id:" + correlationData);
    if (ack) {
        System.out.println("消息发送成功");
    } else {
        System.out.println("消息发送失败:" + cause);
    }
}
 
Example #4
Source File: ProductServiceImpl.java    From jim-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void save(Product product) {

    if(null==product.getId()){
        this.productMapper.insert(product);
    }
    else {
        this.productMapper.updateByPrimaryKey(product);
    }
    String uuid = UUID.randomUUID().toString();
    CorrelationData correlationId = new CorrelationData(uuid);
    rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME, RabbitMQConfig.ROUTING_KEY, product.getName(),correlationId);
}
 
Example #5
Source File: ProductServiceImpl.java    From jim-framework with Apache License 2.0 5 votes vote down vote up
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
    this.logger.info(" 消息id:" + correlationData);
    if (ack) {
        this.logger.info("消息发送确认成功");
    } else {
        this.logger.info("消息发送确认失败:" + cause);

    }
}
 
Example #6
Source File: TestPublisherPublisher.java    From synchronizing-doc-convert-results with Apache License 2.0 5 votes vote down vote up
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
    logger.info("test publisher get confirmed info : " + correlationData);
    if (ack) {
        logger.info("send msg success");
    } else {
        logger.error("send msg failed and the reason is : " + cause);
    }
}
 
Example #7
Source File: QueueJobErrorInfoPublisher.java    From synchronizing-doc-convert-results with Apache License 2.0 5 votes vote down vote up
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
    logger.info("queue job error info service get confirmed info : " + correlationData);
    if (ack) {
        logger.info("send msg success");
    } else {
        logger.error("send msg failed and the reason is : " + cause);
    }
}
 
Example #8
Source File: ConvertDocPublisher.java    From synchronizing-doc-convert-results with Apache License 2.0 5 votes vote down vote up
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
    logger.info("convert doc service get confirmed info : " + correlationData);
    if (ack) {
        logger.info("send msg success");
    } else {
        logger.error("send msg failed and the reason is : " + cause);
    }
}
 
Example #9
Source File: Sender.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * 回调
 */
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
    System.out.println(" 回调id:" + correlationData);
    if (ack) {
        System.out.println("消息成功消费");
    } else {
        System.out.println("消息消费失败:" + cause);
    }
}
 
Example #10
Source File: PublishTraceLog.java    From summerframework with Apache License 2.0 5 votes vote down vote up
public PublishTraceLog(final RabbitTemplate rabbitTemplate, final Channel channel, final String exchange,
    final String routingKey, final Message message, final boolean mandatory,
    final CorrelationData correlationData) {
    this.rabbitTemplate = rabbitTemplate;
    this.channel = channel;
    this.exchange = exchange;
    this.routingKey = routingKey;
    this.message = message;
    this.mandatory = mandatory;
    this.correlationData = correlationData;
}
 
Example #11
Source File: RabbitTemplateExtend.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@Override
public void doSend(Channel channel, String exchange, String routingKey, Message message, boolean mandatory,
    CorrelationData correlationData) throws Exception {

    try {
        PublishTraceLog traceLog =
            new PublishTraceLog(this, channel, exchange, routingKey, message, mandatory, correlationData);
        traceLog.log();
    } catch (Throwable e) {
        LOGGER.warn(e.getMessage(), e);
    }
    try {
        Map<String, Long> delayParam = DELAY_QUEUE_CONTENT.get();
        if (delayParam != null && delayParam.size() == 1) {
            String sourceQueue = delayParam.keySet().iterator().next();
            Long interval = delayParam.get(sourceQueue);
            if (interval > 0) {
                String delayQueue = sourceQueue + DeadLetterConstant.DEFAULT_DELAY_QUEUENAME_PREFIX;
                String delayRouteKey = routingKey + DeadLetterConstant.DEFAULT_DELAY_QUEUENAME_PREFIX;
                deadLetterQueueCreator.createDeadLetterQueue(exchange, routingKey, delayRouteKey, sourceQueue,
                    delayQueue, interval);
                String delayExchange = DeadLetterConstant.DEFAULT_DEADLETTEREXCHANGE_NAME;
                super.doSend(channel, delayExchange, delayRouteKey, message, mandatory, correlationData);
                return;
            }
        }
        super.doSend(channel, exchange, routingKey, message, mandatory, correlationData);
    } finally {
        DELAY_QUEUE_CONTENT.remove();
    }

}
 
Example #12
Source File: RabbitSender.java    From code with Apache License 2.0 5 votes vote down vote up
public void sendOrder(Order order) throws Exception {
	rabbitTemplate.setConfirmCallback(confirmCallback);
	rabbitTemplate.setReturnCallback(returnCallback);
	//id + 时间戳 全局唯一 
	CorrelationData correlationData = new CorrelationData("0987654321");
	rabbitTemplate.convertAndSend("exchange-2", "springboot.def", order, correlationData);
}
 
Example #13
Source File: RabbitSender.java    From code with Apache License 2.0 5 votes vote down vote up
public void send(Object message, Map<String, Object> properties) throws Exception {
	MessageHeaders mhs = new MessageHeaders(properties);
	Message msg = MessageBuilder.createMessage(message, mhs);
	rabbitTemplate.setConfirmCallback(confirmCallback);
	rabbitTemplate.setReturnCallback(returnCallback);
	//id + 时间戳 全局唯一 
	CorrelationData correlationData = new CorrelationData("1234567890");
	rabbitTemplate.convertAndSend("exchange-1", "springboot.abc", msg, correlationData);
}
 
Example #14
Source File: RabbitSender.java    From code with Apache License 2.0 5 votes vote down vote up
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
	System.err.println("correlationData: " + correlationData);
	System.err.println("ack: " + ack);
	if(!ack){
		System.err.println("异常处理....");
	}
}
 
Example #15
Source File: RabbitOrderSender.java    From code with Apache License 2.0 5 votes vote down vote up
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
	System.err.println("correlationData: " + correlationData);
	String messageId = correlationData.getId();
	if(ack){
		//如果confirm返回成功 则进行更新
		brokerMessageLogMapper.changeBrokerMessageLogStatus(messageId, Constants.ORDER_SEND_SUCCESS, new Date());
	} else {
		//失败则进行具体的后续操作:重试 或者补偿等手段
		System.err.println("异常处理...");
	}
}
 
Example #16
Source File: RabbitSender.java    From code with Apache License 2.0 5 votes vote down vote up
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
	System.err.println("correlationData: " + correlationData);
	System.err.println("ack: " + ack);
	if(!ack){
		System.err.println("异常处理....");
	}
}
 
Example #17
Source File: RabbitOrderSender.java    From code with Apache License 2.0 4 votes vote down vote up
public void sendOrder(Order order) throws Exception {
	rabbitTemplate.setConfirmCallback(confirmCallback);
	//消息唯一ID
	CorrelationData correlationData = new CorrelationData(order.getMessageId());
	rabbitTemplate.convertAndSend("order-exchange11", "order.ABC", order, correlationData);
}
 
Example #18
Source File: RabbitmqSendServiceImpl.java    From myth with Apache License 2.0 3 votes vote down vote up
/**
 * Confirmation callback.
 * Message of the Callback, the main is to realize the Rabbit Template.
 * Confirm the Callback interface Note that the message callback can only represent
 * the success message sent to Rabbit MQ server,
 * does not represent a message is successfully processed and accepted
 * @param correlationData correlation data for the callback.
 * @param ack             true for ack, false for nack
 * @param cause           An optional cause, for nack, when available, otherwise null.
 */
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
    if (ack) {
        LogUtil.info(LOGGER, () -> "rabbit mq send message success!");
    } else {
        LogUtil.info(LOGGER, () -> "rabbit mq send message fail!" + cause + " retry send!");

    }
}
 
Example #19
Source File: Coordinator.java    From shine-mq with Apache License 2.0 2 votes vote down vote up
/**
 * 消息发送到RabbitMQ后 自定义ack回调
 *
 * @param correlationData
 * @param ack
 */
void confirmCallback(CorrelationData correlationData, boolean ack);
 
Example #20
Source File: RedisCoordinator.java    From shine-mq with Apache License 2.0 2 votes vote down vote up
@Override
public void confirmCallback(CorrelationData correlationData, boolean ack) {

}
 
Example #21
Source File: SenderService.java    From SpringBootBucket with MIT License 2 votes vote down vote up
/**
 * 测试广播模式.
 *
 * @param p the p
 * @return the response entity
 */
public void broadcast(String p) {
    CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
    rabbitTemplate.convertAndSend("FANOUT_EXCHANGE", "", p, correlationData);
}
 
Example #22
Source File: SenderService.java    From SpringBootBucket with MIT License 2 votes vote down vote up
/**
 * 测试Direct模式.
 *
 * @param p the p
 * @return the response entity
 */
public void direct(String p) {
    CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
    rabbitTemplate.convertAndSend("DIRECT_EXCHANGE", "DIRECT_ROUTING_KEY", p, correlationData);
}