spring-cloud-aws
spring-cloud-aws copied to clipboard
Simplify not adding type header in SqsTemplate sent messages
Currently in order to not add type information to messages sent with the SqsTemplate
it's necessary to do something like this:
SqsTemplate template = SqsTemplate.builder().sqsAsyncClient(this.asyncClient)
.configureDefaultConverter(converter -> converter.setPayloadTypeHeaderValueFunction(msg -> null))
.build();
We could make it more user-friendly and perhaps have a TemplateOptions.doNotAddTypeInformationToSentMessages()
method or something similar.
May I try this one? Seems to be good to start!
Sounds good @levys17!
Let me know if there's anything you'd like to discuss.
Hii, @tomazfernandes!
Considering that AbstractMessagingMessageConverter is responsible to set headers ( typeHeader included), what do you thing about implement this method in this class?
public void sendMessageWithoutTypeHeader() {
this.payloadTypeHeaderFunction = message -> null;
}
@Test
void shouldSendAndReceiveRecordMessageWithoutPayloadInfoHeader() {
SqsTemplate template = SqsTemplate.builder().sqsAsyncClient(this.asyncClient)
.configureDefaultConverter(converter -> converter.sendMessageWithoutTypeHeader())
.build();
SampleRecord testRecord = new SampleRecord("Hello world!",
"From shouldSendAndReceiveRecordMessageWithoutPayloadInfoHeader!");
SendResult<SampleRecord> result = template.send(RECORD_WITHOUT_TYPE_HEADER_QUEUE_NAME, testRecord);
assertThat(result).isNotNull();
Optional<Message<SampleRecord>> receivedMessage = template
.receive(from -> from.queue(RECORD_WITHOUT_TYPE_HEADER_QUEUE_NAME), SampleRecord.class);
assertThat(receivedMessage).isPresent().get().extracting(Message::getPayload).isEqualTo(testRecord);
}
Should I keep going implementing this way or perhaps there is a better way?
Hey @levys17, sorry for the delay!
what do you thing about implement this method in this class?
This makes sense. I had thought of setting it in the ContainerOptions
to try to make it more obvious and easier to find, but maybe it'd just add unnecessary complexity.
Regarding the method name, how about converter.doNotSendTypeHeader()
? Seems a bit more straightforward, but I'm open to suggestions.
Let me know your thoughts, thanks!
No problem, @tomazfernandes! Thanks for answer! Ok, I'll finish the implementation considering this. About the method name, seems really better than I used.
I'll open a PR soon.
Thanks!
@tomazfernandes looks like a good candidate for 3.1.1?
@tomazfernandes looks like a good candidate for 3.1.1?
Yup, definitely!
Fixed in https://github.com/awspring/spring-cloud-aws/pull/1066