Git Product home page Git Product logo

Comments (22)

artembilan avatar artembilan commented on March 29, 2024

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.

garyrussell avatar garyrussell commented on March 29, 2024

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.

OrangeDog avatar OrangeDog commented on March 29, 2024

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.

artembilan avatar artembilan commented on March 29, 2024

It is done only for case, BTW:

CorrelationData correlationData = null;
if (this.enableConfirms) {
	correlationData = new CorrelationData(null);
}

from spring-amqp.

garyrussell avatar garyrussell commented on March 29, 2024

I like the idea of a CorrelationDataAwareMPP - we could avoid having to create an MPP for each request.

from spring-amqp.

garyrussell avatar garyrussell commented on March 29, 2024

https://jira.spring.io/browse/AMQP-697

from spring-amqp.

artembilan avatar artembilan commented on March 29, 2024

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.

OrangeDog avatar OrangeDog commented on March 29, 2024

@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.

garyrussell avatar garyrussell commented on March 29, 2024

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.

OrangeDog avatar OrangeDog commented on March 29, 2024

Aside: in my use case, does anything bad happen if the correlation data id is null?

from spring-amqp.

garyrussell avatar garyrussell commented on March 29, 2024

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.

garyrussell avatar garyrussell commented on March 29, 2024

Which, of course, is not very useful since you can't correlate which message the confirm is for 😄

from spring-amqp.

OrangeDog avatar OrangeDog commented on March 29, 2024

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.

garyrussell avatar garyrussell commented on March 29, 2024

Oh, sorry, I thought you meant the CorrelationData itself was null 😄

from spring-amqp.

garyrussell avatar garyrussell commented on March 29, 2024

@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.

OrangeDog avatar OrangeDog commented on March 29, 2024

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.

garyrussell avatar garyrussell commented on March 29, 2024

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.

OrangeDog avatar OrangeDog commented on March 29, 2024

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.

garyrussell avatar garyrussell commented on March 29, 2024

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.

OrangeDog avatar OrangeDog commented on March 29, 2024

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.

garyrussell avatar garyrussell commented on March 29, 2024

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.

garyrussell avatar garyrussell commented on March 29, 2024

#548

from spring-amqp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.