@Override public void confirm(CorrelationData correlationData, boolean ack, String cause) { final Long id = Long.valueOf(correlationData.getId()); // 当一条消息为PENDING而且ack为true时则删除原有的消息 if (ack) { // flag instead publisherMapper.updateEventStatusByPrimaryKeyInCasMode(id, EventStatus.PENDING, EventStatus.DONE); // 或直接删除 //publisherMapper.deleteByPrimaryKey(id); } else { // 打开mandatory之后,ack为false的情况就是没有找到exchange LOGGER.error("message has failed to found a proper exchange which local id is {}. cause: {}", id, cause); publisherMapper.updateEventStatusByPrimaryKeyInCasMode(id, EventStatus.PENDING, EventStatus.NOT_FOUND); } } }
publish(dto, route.getExchange(), route.getRouteKey(), new CorrelationData(String.valueOf(event.getId())));
public void send() { rabbitTemplatenew.setConfirmCallback(this); String msg="callbackSender : i am callback sender"; System.out.println(msg ); CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); System.out.println("callbackSender UUID: " + correlationData.getId()); this.rabbitTemplatenew.convertAndSend("exchange", "topic.messages", msg, correlationData); }
MessageProperties messageProperties = this.propertiesConverter.toMessageProperties(resp.getProps(), resp.getEnvelope(), StandardCharsets.UTF_8.name()); messageProperties.setConsumerQueue(this.queue); RabbitUtils.closeChannel(channel); RabbitUtils.closeConnection(connection); throw RabbitExceptionTranslator.convertRabbitAccessException(e);
protected RuntimeException convertRabbitAccessException(Exception ex) { return RabbitExceptionTranslator.convertRabbitAccessException(ex); }
@Test public void testInbound() { @SuppressWarnings("unchecked") final Message<String> out = (Message<String>) new ObjectToJsonTransformer() .transform(new GenericMessage<Foo>(new Foo())); MessageProperties messageProperties = new MessageProperties(); DefaultAmqpHeaderMapper.outboundMapper().fromHeadersToRequest(out.getHeaders(), messageProperties); final BasicProperties props = new DefaultMessagePropertiesConverter().fromMessageProperties(messageProperties, "UTF-8"); this.rabbitTemplate.execute(channel -> { channel.basicPublish("", JSON_TESTQ, props, out.getPayload().getBytes()); return null; }); Object received = this.rabbitTemplate.receiveAndConvert(JSON_TESTQ); assertThat(received, instanceOf(Foo.class)); }
@Override public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> desiredResultType) throws EvaluationException { return getValue(context, desiredResultType); }
@Override public void setValue(EvaluationContext context, Object value) throws EvaluationException { setValue(context, null, value); }
/** * Set the mandatory flag when sending messages; only applies if a * {@link #setReturnCallback(ReturnCallback) returnCallback} had been provided. * @param mandatory the mandatory to set. */ public void setMandatory(boolean mandatory) { this.mandatoryExpression = new ValueExpression<>(mandatory); }
@Override public void confirm(CorrelationData correlationData, boolean b, String s) { System.out.println("callbakck confirm: " + correlationData.getId()); } }
protected RuntimeException convertRabbitAccessException(Exception ex) { return RabbitExceptionTranslator.convertRabbitAccessException(ex); }
@Override public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> desiredResultType) throws EvaluationException { return getValue(context, desiredResultType); }
@Override public void setValue(Object rootObject, Object value) throws EvaluationException { setValue(null, rootObject, value); }
/** * Set the mandatory flag when sending messages; only applies if a * {@link #setReturnCallback(ReturnCallback) returnCallback} had been provided. * @param mandatory the mandatory to set. */ public void setMandatory(boolean mandatory) { this.mandatoryExpression = new ValueExpression<>(mandatory); }
@Override public void afterPropertiesSet() { try { super.afterPropertiesSet(); } catch (Exception e) { throw RabbitExceptionTranslator.convertRabbitAccessException(e); } }
@Override public <T> T getValue(Object rootObject, Class<T> desiredResultType) throws EvaluationException { return getValue(desiredResultType); }
@Override public void setValue(EvaluationContext context, Object value) throws EvaluationException { setValue(context, null, value); }
throw RabbitExceptionTranslator.convertRabbitAccessException(e);
@Override public <T> T getValue(Object rootObject, Class<T> desiredResultType) throws EvaluationException { return getValue(desiredResultType); }
@Override public void setValue(Object rootObject, Object value) throws EvaluationException { setValue(null, rootObject, value); }