Cant convert incoming message from RabbitMQ queue

Message converter in my rabbitmqconfig file:
@Bean
public Jackson2JsonMessageConverter jsonMessageConverter() {
ObjectMapper objectMapper = new ObjectMapper();
return new Jackson2JsonMessageConverter(objectMapper);
}
@Bean
public Jackson2JsonMessageConverter jsonMessageConverter() {
ObjectMapper objectMapper = new ObjectMapper();
return new Jackson2JsonMessageConverter(objectMapper);
}
Consumer class:
@RabbitListener(queues = "${broker.queue.email.name}")
public void listenerEmailQueue(Message<EmailNotificationDto> emailRequest) {

System.out.println(emailRequest.getPayload().getItem());
}
@RabbitListener(queues = "${broker.queue.email.name}")
public void listenerEmailQueue(Message<EmailNotificationDto> emailRequest) {

System.out.println(emailRequest.getPayload().getItem());
}
And i get the following error whenever a message is consumed: org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Listener method could not be invoked with the incoming message No converter found from actual payload type 'byte[]' to expected payload type Anyone able to help please?
82 Replies
JavaBot
JavaBot3mo ago
This post has been reserved for your question.
Hey @Victor! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Victor
VictorOP3mo ago
Still open
ayylmao123xdd
ayylmao123xdd3mo ago
what if you pass email notification dto as the argument instead of message<emailnotificationdto>
Victor
VictorOP3mo ago
thats what i was doing before and i was getting the same error
ayylmao123xdd
ayylmao123xdd3mo ago
show how you were doing it
Victor
VictorOP3mo ago
@RabbitListener(queues = "${broker.queue.email.name}")
public void listenerEmailQueue(EmailNotificationDto emailRequest) {

//System.out.println(emailRequest.getPayload().getItem());
System.out.println(emailRequest.getItem());
@RabbitListener(queues = "${broker.queue.email.name}")
public void listenerEmailQueue(EmailNotificationDto emailRequest) {

//System.out.println(emailRequest.getPayload().getItem());
System.out.println(emailRequest.getItem());
ayylmao123xdd
ayylmao123xdd3mo ago
show rabbit config
Victor
VictorOP3mo ago
@Configuration
public class RabbitMQConfig {

@Value("${broker.queue.email.name}")
private String queue;

@Bean
public Queue queue() {
return new Queue(queue, true);
}
@Bean
public Jackson2JsonMessageConverter jsonMessageConverter() {
ObjectMapper objectMapper = new ObjectMapper();
return new Jackson2JsonMessageConverter(objectMapper);
}

@Bean
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate template = new RabbitTemplate(connectionFactory);
template.setMessageConverter(jsonMessageConverter());
return template;
}

@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
ConnectionFactory connectionFactory) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setMessageConverter(jsonMessageConverter());
return factory;
}
}
@Configuration
public class RabbitMQConfig {

@Value("${broker.queue.email.name}")
private String queue;

@Bean
public Queue queue() {
return new Queue(queue, true);
}
@Bean
public Jackson2JsonMessageConverter jsonMessageConverter() {
ObjectMapper objectMapper = new ObjectMapper();
return new Jackson2JsonMessageConverter(objectMapper);
}

@Bean
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate template = new RabbitTemplate(connectionFactory);
template.setMessageConverter(jsonMessageConverter());
return template;
}

@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
ConnectionFactory connectionFactory) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setMessageConverter(jsonMessageConverter());
return factory;
}
}
i was also trying with just the message converter but same issue
ayylmao123xdd
ayylmao123xdd3mo ago
interesting can u show producer sending to queue also show the dto
Victor
VictorOP3mo ago
producer config:
@Configuration
public class RabbitMQConfig {

@Bean
public Jackson2JsonMessageConverter messageConverter() {
ObjectMapper objectMapper = new ObjectMapper();
return new Jackson2JsonMessageConverter(objectMapper);
}

@Bean
public RabbitTemplate rabbitTemplate(Jackson2JsonMessageConverter jsonMessageConverter) {

RabbitTemplate rabbitTemplate = new RabbitTemplate();
rabbitTemplate.setMessageConverter(jsonMessageConverter);

return rabbitTemplate;
}
}
@Configuration
public class RabbitMQConfig {

@Bean
public Jackson2JsonMessageConverter messageConverter() {
ObjectMapper objectMapper = new ObjectMapper();
return new Jackson2JsonMessageConverter(objectMapper);
}

@Bean
public RabbitTemplate rabbitTemplate(Jackson2JsonMessageConverter jsonMessageConverter) {

RabbitTemplate rabbitTemplate = new RabbitTemplate();
rabbitTemplate.setMessageConverter(jsonMessageConverter);

return rabbitTemplate;
}
}
producer:
EmailNotificationDto sellerNotification = new EmailNotificationDto(item.getSeller().getUsername(), "sale", item.getName());
EmailNotificationDto buyerNotification = new EmailNotificationDto(buyer.get().getUsername(), "purchase", item.getName());

rabbitTemplate.convertAndSend("", routingKey, buyerNotification);
rabbitTemplate.convertAndSend("", routingKey, sellerNotification);
EmailNotificationDto sellerNotification = new EmailNotificationDto(item.getSeller().getUsername(), "sale", item.getName());
EmailNotificationDto buyerNotification = new EmailNotificationDto(buyer.get().getUsername(), "purchase", item.getName());

rabbitTemplate.convertAndSend("", routingKey, buyerNotification);
rabbitTemplate.convertAndSend("", routingKey, sellerNotification);
producer dto:
public record EmailNotificationDto(
String receiver,
String notificationType,
String item
) {
}
public record EmailNotificationDto(
String receiver,
String notificationType,
String item
) {
}
consumer dto:
public record EmailDTO(
String receiver,
String notificationType,
String item
) {
}
public record EmailDTO(
String receiver,
String notificationType,
String item
) {
}
ayylmao123xdd
ayylmao123xdd3mo ago
dont you need to set connection factory for rabbit template
Victor
VictorOP3mo ago
the message was being sent from the producer to the queue, i could see it in the rabbitmq manager
Victor
VictorOP3mo ago
No description
Victor
VictorOP3mo ago
i did add the connection factory to the producer
ayylmao123xdd
ayylmao123xdd3mo ago
so it sees it as json ill check it later
Victor
VictorOP3mo ago
thank you
JavaBot
JavaBot3mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
ayylmao123xdd
ayylmao123xdd3mo ago
hmmmmmmmmmmmm what if you do something like this
@RabbitListener(queues = "${broker.queue.email.name}")
public void listenerEmailQueue(Message emailRequest) {

System.out.println(emailRequest.getPayload());

}
@RabbitListener(queues = "${broker.queue.email.name}")
public void listenerEmailQueue(Message emailRequest) {

System.out.println(emailRequest.getPayload());

}
does this work
Victor
VictorOP3mo ago
this is the output: [B@f1175f8 [B@3ed5ab18
ayylmao123xdd
ayylmao123xdd3mo ago
very interesting can you try casting the payload to your dto see if that works
Victor
VictorOP3mo ago
like (EmailDTO) emailRequest.getPayload()?
ayylmao123xdd
ayylmao123xdd3mo ago
yea something like that
Victor
VictorOP3mo ago
class [B cannot be cast to class com.vss.ms_resell_emailService.consumer.EmailNotificationDto
ayylmao123xdd
ayylmao123xdd3mo ago
hmmmmmmmm maybe thats something with the record can you make a no args constructor for email notification dto and go back to dto in the parameter wait nvm i just tested it locally and thats not the problem
Victor
VictorOP3mo ago
i asked someone else and they said it might have something to do with the type id but i recreated the exact same class and still getting the same error
ayylmao123xdd
ayylmao123xdd3mo ago
yea give me a few min ill make the exact same copy and check whats wrong hmmmmmmmmm can you delete the rabbit template bean maybe that config is doing something wrong i just made a minimal reproducer and its working fine so idk do you have some link so i can see the classes also delete the simple message link listener factory i dont think its necessary
Victor
VictorOP3mo ago
keep just the message converter?
ayylmao123xdd
ayylmao123xdd3mo ago
yea the rest should be auto fconfigured for the rest template
Victor
VictorOP3mo ago
same error still i can upload the project to github
ayylmao123xdd
ayylmao123xdd3mo ago
ok make it public and send link ill just copy the exact classes and check it at my own crazy machine
Victor
VictorOP3mo ago
GitHub
GitHub - 1VSS/ms-resell-email: Email notification microservice for ...
Email notification microservice for the reselling API - 1VSS/ms-resell-email
ayylmao123xdd
ayylmao123xdd3mo ago
gonna check now
Victor
VictorOP3mo ago
🤙
ayylmao123xdd
ayylmao123xdd3mo ago
@Bean
public Jackson2JsonMessageConverter jsonMessageConverter() {
ObjectMapper objectMapper = new ObjectMapper();
return new Jackson2JsonMessageConverter(objectMapper);
}
@Bean
public Jackson2JsonMessageConverter jsonMessageConverter() {
ObjectMapper objectMapper = new ObjectMapper();
return new Jackson2JsonMessageConverter(objectMapper);
}
switch to
@Bean
public Jackson2JsonMessageConverter jsonMessageConverter() {
return new Jackson2JsonMessageConverter();
}
@Bean
public Jackson2JsonMessageConverter jsonMessageConverter() {
return new Jackson2JsonMessageConverter();
}
also print the stack trace of the whole error i mean just send it
Victor
VictorOP3mo ago
i've tried that
Victor
VictorOP3mo ago
ayylmao123xdd
ayylmao123xdd3mo ago
oh so its jackson problem have you tested it locally like made a queue with docker i copied the setup and it works when i send to my queue with docker or maybe theres something wrong with the producer
Victor
VictorOP3mo ago
i tried publishing with the cloudAMQP manager and got the same error still
No description
ayylmao123xdd
ayylmao123xdd3mo ago
hmmm ok lets ask someone else
Victor
VictorOP3mo ago
i think i'll just redo everything, cant figure out whats going on
ayylmao123xdd
ayylmao123xdd3mo ago
@dan1st can u check cant serialize to object from byte[] with rabbitmq at consumer
ayylmao123xdd
ayylmao123xdd3mo ago
GitHub
GitHub - 1VSS/ms-resell-email: Email notification microservice for ...
Email notification microservice for the reselling API - 1VSS/ms-resell-email
ayylmao123xdd
ayylmao123xdd3mo ago
wait did you recompile target after each change or no
Victor
VictorOP3mo ago
yea but the consumer im just running the application off the IDE
ayylmao123xdd
ayylmao123xdd3mo ago
lol can you try sending just a string instead of dto and see if that will work
Victor
VictorOP3mo ago
i did that at first and it worked i could receive and print the string but when i changed to receive an object it started with the errors its my first time using rabbitmq so its just a small project to try it out
ayylmao123xdd
ayylmao123xdd3mo ago
i mean wait can you make a producer in the same project where you have the consumer just copy the class that sends and see if that is gonna work
Victor
VictorOP3mo ago
yea, sec java.lang.IllegalArgumentException: SimpleMessageConverter only supports String, byte[] and Serializable payloads, received: com.vss.ms_resell_emailService.consumer.EmailNotificationDto at org.springframework.amqp.support.converter.SimpleMessageConverter.createMessage(SimpleMessageConverter.java:143) ~[spring-amqp-3.2.6.jar:3.2.6] at org.springframework.amqp.support.converter.AbstractMessageConverter.createMessage(AbstractMessageConverter.java:88) ~[spring-amqp-3.2.6.jar:3.2.6] at org.springframework.amqp.support.converter.AbstractMessageConverter.toMessage(AbstractMessageConverter.java:70) ~[spring-amqp-3.2.6.jar:3.2.6] at org.springframework.amqp.support.converter.AbstractMessageConverter.toMessage(AbstractMessageConverter.java:58) ~[spring-amqp-3.2.6.jar:3.2.6] at org.springframework.amqp.rabbit.core.RabbitTemplate.convertMessageIfNecessary(RabbitTemplate.java:1905) ~[spring-rabbit-3.2.6.jar:3.2.6] at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:1201) ~[spring-rabbit-3.2.6.jar:3.2.6] at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:1194) ~[spring-rabbit-3.2.6.jar:3.2.6] at com.vss.ms_resell_emailService.controller.TestController.publish(TestController.java:25) ~[classes/:na]
ayylmao123xdd
ayylmao123xdd3mo ago
now that gives us something
Victor
VictorOP3mo ago
@RestController
public class TestController {

private final RabbitTemplate rabbitTemplate;

public TestController(RabbitTemplate rabbitTemplate) {
this.rabbitTemplate = rabbitTemplate;
}

@Value("${broker.queue.email.name}")
private String routingKey;

@PostMapping
public void publish(@RequestBody EmailNotificationDto emailNotificationDto) {

rabbitTemplate.convertAndSend("", routingKey, emailNotificationDto);
}
}
@RestController
public class TestController {

private final RabbitTemplate rabbitTemplate;

public TestController(RabbitTemplate rabbitTemplate) {
this.rabbitTemplate = rabbitTemplate;
}

@Value("${broker.queue.email.name}")
private String routingKey;

@PostMapping
public void publish(@RequestBody EmailNotificationDto emailNotificationDto) {

rabbitTemplate.convertAndSend("", routingKey, emailNotificationDto);
}
}
this is what i tested with
ayylmao123xdd
ayylmao123xdd3mo ago
can you do email notification dto extends serializable and then check
Victor
VictorOP3mo ago
ayylmao123xdd
ayylmao123xdd3mo ago
yea try setting that in application yml for testing purposes spring.amqp.deserialization.trust.all to true
dan1st
dan1st3mo ago
Where is the byte[]?
ayylmao123xdd
ayylmao123xdd3mo ago
listener reads content as bytes but doesnt transform to dto
dan1st
dan1st3mo ago
also I think that specific class should be trusted instead of all classes
ayylmao123xdd
ayylmao123xdd3mo ago
testing purposes
dan1st
dan1st3mo ago
Where is the listener?
ayylmao123xdd
ayylmao123xdd3mo ago
github
ayylmao123xdd
ayylmao123xdd3mo ago
GitHub
GitHub - 1VSS/ms-resell-email: Email notification microservice for ...
Email notification microservice for the reselling API - 1VSS/ms-resell-email
dan1st
dan1st3mo ago
strategy pattern lol
Victor
VictorOP3mo ago
im just using it to experiment with new stuff 😔 is that bad
dan1st
dan1st3mo ago
anyway I don't really see any specific thing about byte[]s there? Is EmailConsumer the listener you were talking about? it's perfectly fine, I just saw it
Victor
VictorOP3mo ago
yeah the email consumer is the listener, whenever it receives the message it says it cant convert byte to the emailNotificationDto
ayylmao123xdd
ayylmao123xdd3mo ago
heres stack trace did you try if it works with the trust all
dan1st
dan1st3mo ago
Do you have any MessageConverter defined anywhere?
dan1st
dan1st3mo ago
If so, you can also set allowed patterns there as shown here: https://stackoverflow.com/a/78064593/10871900
Stack Overflow
Spring Boot RabbitMQ RabbitListener ListenerExecutionFailedException
org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Failed to convert message at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(
ayylmao123xdd
ayylmao123xdd3mo ago
there is message converter yes same setup works for me locally btw
dan1st
dan1st3mo ago
Can you try adding implements Serializable to EmailNotificationDto? just for testing
ayylmao123xdd
ayylmao123xdd3mo ago
he did
dan1st
dan1st3mo ago
ah ok
Victor
VictorOP3mo ago
i added spring.amqp.deserialization.trust.all=true to my application.properties but still says unauthorized
ayylmao123xdd
ayylmao123xdd3mo ago
you got application properties or yml on github its yml
Victor
VictorOP3mo ago
application properties
ayylmao123xdd
ayylmao123xdd3mo ago
oh
Victor
VictorOP3mo ago
are you sure
ayylmao123xdd
ayylmao123xdd3mo ago
oh its properties lmfao
dan1st
dan1st3mo ago
I think you can add that method to the RabbitMQConfig
@Bean("methodConverter")
public SimpleMessageConverter methodMessageConverter() {
SimpleMessageConverter converter = new SimpleMessageConverter();
converter.setAllowedListPatterns(List.of("**com.vss.ms_resell_emailService.consumer.**"));
return converter;
}
@Bean("methodConverter")
public SimpleMessageConverter methodMessageConverter() {
SimpleMessageConverter converter = new SimpleMessageConverter();
converter.setAllowedListPatterns(List.of("**com.vss.ms_resell_emailService.consumer.**"));
return converter;
}
if you don't want to trust all types but for now, adding the property to the application.properties is fine
ayylmao123xdd
ayylmao123xdd3mo ago
i mean it works for me locally so maybe the queue is the problem its some external one not local
Victor
VictorOP3mo ago
im just gonna start it over from scratch, i think this has bothered you all too long already. I appreciate the help tho
JavaBot
JavaBot3mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?