Spring boot and CloudEvent AMQP binding

800 views Asked by At

I'm trying to implement some CloudEvent demo.
I have a hew spring boot services with RabbitMQ as a message bus they all send messages to a queue and one listens to the queue messages.
I try to wrap my messages as CloudEvent to make them more standard.
I use the following code to wrap the message (data) as a CloudEvent.

try {
    inputEvent = CloudEventBuilder.v1()
            .withSource(new URI("app://" + messageData.getChangeRequestId().toString()))
            .withDataContentType("application/json")
            .withId(messageData.myId().toString())
            .withType("com.data.BaseMessageData")
            .withData(objMapper.writeValueAsBytes(eventData))
            .build();

} catch (Exception e) {
   throw new MyMessagingException("Failed to convert the message into json. (See inner exception for further details)", e);
}

The data is converted to bytes since the message CloudEventData is based on bytes.
Of course, that on my listener method I get exception since SimpleMessageConverter can't handle bytes array. Now, I can try and implement some custom message handler or try to check out CloudEvent AMQP suggested binding solution but I'm not keen with the amount of code it involves and I don't want to involve more technologies if not absolutely necessary.

  1. Should I go down this path and implement a custom message conveter?
  2. Is there any other standard solution for standardizing services messaging over qeueus?
1

There are 1 answers

0
Gary Russell On

You will need a custom message converter; but see this blog post:

https://spring.io/blog/2020/12/10/cloud-events-and-spring-part-1