Comments (22)
That CorrelationData.setId()
is intended for internal use.
And Framework has only one place for that case - AsyncRabbitTemplate.CorrelationMessagePostProcessor
What is your use-case, please?
from spring-amqp.
Interesting observation - I added that javadoc recently when I implemented the AsyncRabbitTemplate
- as you can see, the MPP is stateful and gets a reference to the CorrelationData
(each send gets its own MPP)...
private final class CorrelationMessagePostProcessor<C> implements MessagePostProcessor {
private final MessagePostProcessor userPostProcessor;
private final CorrelationData correlationData;
private final ParameterizedTypeReference<C> returnType;
private volatile RabbitConverterFuture<C> future;
CorrelationMessagePostProcessor(MessagePostProcessor userPostProcessor,
CorrelationData correlationData, ParameterizedTypeReference<C> returnType) {
this.userPostProcessor = userPostProcessor;
this.correlationData = correlationData;
this.returnType = returnType;
}
@Override
public Message postProcessMessage(Message message) throws AmqpException {
Message messageToSend = message;
if (this.userPostProcessor != null) {
messageToSend = this.userPostProcessor.postProcessMessage(message);
}
String correlationId = getOrSetCorrelationIdAndSetReplyTo(messageToSend);
this.future = new RabbitConverterFuture<C>(correlationId, message);
if (this.correlationData != null && this.correlationData.getId() == null) {
this.correlationData.setId(correlationId);
this.future.setConfirm(new SettableListenableFuture<>());
}
this.future.setReturnType(this.returnType);
AsyncRabbitTemplate.this.pending.put(correlationId, this.future);
return messageToSend;
}
private RabbitConverterFuture<C> getFuture() {
return this.future;
}
}
from spring-amqp.
Specifically, to generate CorrelationData
from the Message
in a uniform way, without having to add extra calls for every send
call. I'm only using it for publisher confirms, not replies, so AsyncRabbitTemplate
doesn't seem to be the right solution.
Even more specifically, I want to use the whole Message
as CorrelationData
, so I have exactly the same information available from ReturnCallback
, ConfirmCallback
and getUnconfirmed
. However, I'm also using sendAndConvert
, so the only place I'll have a Message
before it's sent is in MessagePostProcessor
(or a custom MessageConverter
, but it makes less sense for that to be aware of CorrelationData
).
from spring-amqp.
It is done only for case, BTW:
CorrelationData correlationData = null;
if (this.enableConfirms) {
correlationData = new CorrelationData(null);
}
from spring-amqp.
I like the idea of a CorrelationDataAwareMPP
- we could avoid having to create an MPP for each request.
from spring-amqp.
https://jira.spring.io/browse/AMQP-697
from spring-amqp.
Right, now you have to do that manually in advance before calling:
public void convertAndSend(String exchange, String routingKey, final Object message,
final MessagePostProcessor messagePostProcessor, CorrelationData correlationData) throws AmqpException {
or just
convertAndSend(String routingKey, final Object object, CorrelationData correlationData)
At least that how it has been designed to use...
from spring-amqp.
@artembilan there's more detail in my explanation now, I want to make the correlation data after the message converter.
@garyrussell any chance of that making it for 1.6.7?
from spring-amqp.
Not if we use a default
method on MPP for the implementation (requires Java 8).
If we go with a sub-interface, we could backport to 1.6.x.
from spring-amqp.
Aside: in my use case, does anything bad happen if the correlation data id is null
?
from spring-amqp.
Nothing bad, as long as you handle getting null
back in the ConfirmCallback
. The template doesn't look at the data at all.
from spring-amqp.
Which, of course, is not very useful since you can't correlate which message the confirm is for 😄
from spring-amqp.
you can't correlate which message the confirm is for
Well I can when the rest of the correlation data is whatever I want.
public CorrelationDataAdaptor(Object delegate) {
super(null);
this.delegate = delegate;
}
from spring-amqp.
Oh, sorry, I thought you meant the CorrelationData
itself was null 😄
from spring-amqp.
@OrangeDog This will be in the 1.6.7 release; the master PR is ready for review and I'll back port it after review/merge.
from spring-amqp.
Sorry, I should have had a look at the change sooner.
This still doesn't let you add a Correlation
if one doesn't exist. That's all I was asking for.
from spring-amqp.
We can't really do that without adding a whole new interface and callback. You will need to add an empty correlation container to the send and update it in the MPP.
from spring-amqp.
adding a whole new interface and callback
That is what I was asking for.
some kind of
public CorrelationData postProcessCorrelationData(CorrelationData data, Message message)
API?
from spring-amqp.
We could have done that (and I now see it in your original post where you "presumed" that was the intent of the javadoc, but the javadoc explicitly referenced MessagePostProcessor
not some new interface.
To be honest, the original intent was something like this
final CorrelationData foo = ...
template.send(..., ..., m -> {
// update message
foo.setSomething(...);
});
We're planning on releasing today so I don't think we can change direction at this point.
What is the objection to adding a container object before the send?
from spring-amqp.
Specifically, to generate CorrelationData from the Message in a uniform way, without having to add extra calls for every send call.
There are lots of send calls in my codebase, you have to use the full RabbitTemplate
interface and 4-ary method, and I'd rather not have to change every single one.
I appreciate it's a bit late now, but please leave this open for future consideration.
from spring-amqp.
OK; you convinced me 😄 - we'll try to get it out today, but it may cause the release to be pushed to tomorrow.
from spring-amqp.
from spring-amqp.
Related Issues (20)
- Get rid of `synchronized` in `RabbitAdmin`
- Get rid of `synchronized` in `RabbitTemplate` HOT 1
- Get rid of `synchronized` in the `BlockingQueueConsumer`
- Get rid of `synchronized` in `spring-rabbit-test` module
- Get rid of the rest of `synchronized` in the ListenerContainer infrastructure
- Improve Extensibility of RepublishMessageRecovererWithConfirms by supporting SpEL expressions HOT 1
- AmqpRejectAndDontRequeueException completely restarts Consumer HOT 2
- The `SimpleMessageListenerContainer` does not shutdown properly
- The `SimpleMessageListenerContainer` does not shutdown properly HOT 1
- Swallowed exception 'AmqpTimeoutException: No available channels' HOT 4
- Add batchReceiveTimeout in SimpleMessageListenerContainer HOT 3
- MessageProperties setDelay maximum value problem HOT 3
- ImmediateAcknowledgeAmqpException keeps the message in the queue HOT 10
- TraceId propagation to the new thread local HOT 4
- Wrong ClassLoader is used for message deserialization when devtools are active
- Wrong ClassLoader is used for message deserialization when devtools are active HOT 1
- Kotlin suspend functions return type is incorrect HOT 1
- Kotlin suspend functions return type is incorrect HOT 1
- Channel cache leak when no answers from broker for pending confirms
- Channel cache leak when no answers from broker for pending confirms HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-amqp.