Solace Spring cloud stream, DLQ exception headers

akg17
akg17 Member Posts: 76

There was exception thrown from the service and the message went to DLQ, when i pulled it from queue and checked there is no way to get why the exception was thrown.

Rabbit has the headers like x-exception-stacktrace, x-exception-message where i can get enough details about it, there could be so many message in DLQ so i need to save them into database along with the exception message, stack trace.

Is there any way with solace spring cloud stream binders i can get the exception stack trace ?

Comments

  • akg17
    akg17 Member Posts: 76

    @marc This is urgent please let me know if there is any way,

  • Tamimi
    Tamimi Member, Administrator, Employee Posts: 491 admin

    Hey @akg17 ! Are you able to provide more details on the exception you received in your spring cloud stream application? As far as I know, the solace spring cloud stream binder does not set a custom message property or header (i.e. x-exception-stacktrace) to include the stack trace

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 914 admin
    edited January 2022 #4

    Hi @akg17,

    Assuming your code is throwing an Exception I believe the only way to access the actual ErrorMessage is by listening to one of the error channels. You can choose to listen to a globalError channel (for all functions in your app) or to a specific one. Search for "Consumer Error Channel" in Section 9 of this codelab and you'll find an example. From inside of that @ServiceActivator you could then use StreamBridge to publish where you want it to go.

    Another option, which might keep it a bit simpler, would be to catch your exception, put it into a header and then publish to a different topic directly from your initial function.

    That all said, can I get you to please open an enhancement request on the solace-spring-cloud github requesting the header be added like the Rabbit binder has? I thought when we looked at that previously the framework didn't allow it but maybe something has changed or maybe we missed something.

    Hope that helps!

  • akg17
    akg17 Member Posts: 76

    I Can raise enhancement request would it be possible to set the exception stack trace & message info in header before publishing to DLQ. those headers ae rabbit specific headers but later when you look into the saved message and headers and you can understand what was the exception, technical or business so that way we can again drop the same message either by changing something or same message again, This could be a good enhancement.

    @Tamimi You are right, they are rabbit specific headers but rabbit sets those property along with the original queue name from where the exception was thrown this helps pulling the message and reprocessing them. we can understand why the exception was thrown from the stack trace else we need to check logs.

    I wanted to get same functionality here too instead of writing code for service activator.
    These will be custom headers that solace binder can set before publishing the message to DLQ.

    "exception-stacktrace":"stackTrace"

    "exception-message": "Destination [QueueName] not found in JNDI; nested exception is javax.naming.NameNotFoundException: JNDI lookup of \"QueueName\" failed - not found".

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 914 admin

    Hi @akg17,

    I Can raise enhancement request would it be possible to set the exception stack trace & message info in header before publishing to DLQ

    Yes exactly, if you can request this in an enhancement we'll look into it further. There is a good chance we will do something the same/similar to the Rabbit Binder, but we will also work with the Cloud Stream framework lead to see if there is something that should be standardized framework wide for all binder that support this feature for consistency.

    Thanks!

  • akg17
    akg17 Member Posts: 76

    https://github.com/SolaceProducts/solace-spring-cloud/issues/115
    @marc Raised one request here. Thanks,
    Please make sure they look into it, its important for our apps,

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 914 admin

    Thanks for opening that @akg17. I'll be sure to get it in front of the R&D team :)

  • akg17
    akg17 Member Posts: 76

    @marc Can You please let me know the status of above request, If they are planning to add that enhancement. I have to find a way to add the exception into the dead letter queue message. To investigate the issue we need to find the exception stack trace but we are only seeing the message.

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 914 admin

    Hi @akg17,

    I checked with our PLM team today to see the status of this. We are planning on adding it, but it isn't scheduled to be worked until late June at the earliest. So besides waiting,

    I think there are 2 options here:

    1. The binder is open source -> you can make a PR against the binder adding this functionality in. I don't think it should be super complex since the Rabbit binder can act as a blueprint. The one thing that might be a bit tricky is figuring out how large of an exception to allow before truncating it. We obviously don't want the addition of the header to cause sending to the error queue to fail.
    2. A bit more work, but Customize your error handling within your apps by ensuring you catch all exceptions, add them to a header and publish to a topic of your choice. This could actually prove more powerful as you could publish different exceptions to different topics to be handled by different error handlers. Going this route you could also add a binding specific error channel listener for each binding. These listeners will receive the Spring ErrorMessage which I believe contains both the exception and the original message.

    Hope that helps!