The Spring documentation mentions one of the core features of the framework:
It tries to automatically convert incoming message payloads to type
Person
with the following code:
@Bean public Consumer<Person> log() {
return person -> {
System.out.println("Received: " + person);
};
}
My attempts to have the incoming message automatically convert into a Person type with Solace have failed.
Please point me to an Solace example of sending & receiving messages thru Spring Cloud Stream where the incoming message payload is automatically converted.
By default when coding your Spring Cloud Stream microservice you are writing Spring Cloud Function beans that can be re-used for multiple purposes and can leverage the framework’s
Content Type Negotiation
to pass your POJOs directly into the function while decoupling your business logic from the specific runtime target and triggering mechanism (web endpoint, stream processor, task).
Hi @dakotahnorth , welcome to the Community. You’re going to need some way to deserialize the payload into your POJO. What format is your payload in? Spring can’t just guess how to do this.
Well … from the Solace AWS Broker “Try Me!” page I tried sending both binary and text messages.
The payload in the message text box was
{\"name\":\"Miles Archer\"}
Changed my simple PersonEvent to be
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PersonEvent {
@JsonProperty("name")
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public PersonEvent(String name) {
this.name = name;
}
public PersonEvent() {
}
Still … I am not able to deserialize the message.
So was hoping there was some lab or github examples with Solace that you can point me to that has this all working with both publishing and receiving messages.
@dakotahnorth , as you see in the Spring Cloud Stream documentation the framework automatically provides this deserialization for you as long as it can understand the payload.
Note that the framework provides these MessageConverters and if you need others you can see the “User-defined Message Converters” section right after that one.
FYI @Aaron no need to do the serialization and deserialization yourself!
Urgh … so embarrassing! Since the documentation had the Person class as part of the same class, I just figured it was the “correct” way.
Thank you for point that out, as well as, the quotes!
When you commented this which sample are you referring to? It’s been a bit since I looked through these samples, but usually we use MessageBuilder when we are trying to show adding message headers.
The sink example is helpful … and for “the simplest of examples”, would be great to see this be even simpler!