Skip to content

Support @SqsHandler routing for Message<T> parameters #1587

Description

@dbouclier

Type: Bug

Component:
"SQS"

Describe the bug
When using @SqsListener with multiple @SqsHandler methods, if a handler method is Message<'Pojo'> instead of just 'Pojo', routing always falls through to the default handler.

Sample

Using Spring boot 3.x and spring cloud aws 4.0.0

// This WORKS — Pojo parameter
 @SqsListener(queueNames = "myQueue")
 public class WorkingListener {

     @SqsHandler
     public void onCreated(MyPojo event) {
         // Correctly routed
     }

     @SqsHandler
     public void onUpdated(MyOtherPojo event) {
         // Correctly routed
     }

     @SqsHandler(isDefault = true)
     public void onDefault(Event event) {
         // Only receives truly unmatched events
     }
 }

 // This FAILS — Message<Pojo> parameter
 @SqsListener(queueNames = "myQueue")
 public class BrokenListener {

     @SqsHandler
     public void onCreated(Message<Pojo> message) {
         // Never reached — falls through to default
     }

     @SqsHandler
     public void onUpdated(Message<MyOtherPojo> message) {
         // Never reached — falls through to default
     }

     @SqsHandler(isDefault = true)
     public void onDefault(Event event) {
         // ALL events end up here
     }
 }

Workaround

Add the POJO as the first parameter for routing, and Message as a second parameter:

 @SqsHandler
 public void onCreated(Pojo pojo, Message<Pojo> message) {
     // 'pojo' enables correct routing with access to message metadata
 }

``

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: sqsSQS integration related issuetype: enhancementSmaller enhancement in existing integration

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions