Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sleuth295] Exception Handling #4

Open
testark opened this issue Jun 8, 2016 · 7 comments
Open

[sleuth295] Exception Handling #4

testark opened this issue Jun 8, 2016 · 7 comments

Comments

@testark
Copy link

testark commented Jun 8, 2016

Hi @garyrussell. First of all, many thanks for taking the time to put up sleuth295 (it really, really helped me grasp the concept). 👍 for that!

I have a question though... Let's imagine that SomeServiceImpl made some validations and threw an IllegalArgumentException (or some other custom RuntimeException). How can this or any other exception be sent as a reply back to Client, so that it can not only receive a valid return value but also handle exceptions with a standard catch clause?

@garyrussell
Copy link
Owner

Hi @testark I am glad you "found" it - I meant to put a link to it on spring-cloud/spring-cloud-sleuth#295

Yes, to reproduce the exception propagation that is handled by remoting needs a little more work.

I just pushed another commit to show the technique - hopefully it's self-explanatory.

FYI, I will be traveling for the next couple of weeks and likely won't be online much, if at all.

/cc @artembilan

@artembilan
Copy link

For the record the question has begun from here: http://stackoverflow.com/questions/37689582/spring-boot-spring-integration-amqp

@testark
Copy link
Author

testark commented Jun 8, 2016

@garyrussell @artembilan thank you very much to both of you, really :-) It was @artembilan that gave me the link. This was a life saver, so many many thanks indeed 👍

@testark
Copy link
Author

testark commented Jun 9, 2016

@garyrussell @artembilan if you don't mind, I'd just like to ask one final question. How do I plug-in the bundled Kryo codec so that messages are Kryo-serialized instead of Java-serialized?

@garyrussell
Copy link
Owner

@testark The message conversion is actually done by Spring AMPQ, not Spring Integration; it doesn't currently have a kryo implementation (only Java and Json).

Spring Integration does, however, provide transformer implementations (PayloadEncodingTransformer, DecodingTransformer) which can be configured as a @Bean with a Kryo codec.

Then, all you need to do is add a .transform(transformer()) on each side, before/after the Amqp gateway in the integration flow, where transformer() is the appropriate transformer bean.

The Spring AMQP "conversion" then becomes a pass-through because the payload is already a byte[].

@artembilan
Copy link

Note. Since EncodingPayloadTransformer (as well as DecodingTransformer) has only one constructor option, there is no need to declare it as a @Bean.
You can just do:

.transform(new EncodingPayloadTransformer(kryoCode()))
...
.transform(new DecodingTransformer(kryoCode(), Foo.class))

and Java DSL will take care about bean for you.
Just less boilerplate code! 😄

I have just raised https://github.com/spring-projects/spring-integration-java-dsl/issues/86 to make it more straightforward in the SI Java DSL.

@testark
Copy link
Author

testark commented Jun 9, 2016

@garyrussell @artembilan thank you very much for all your support, really! It has been a life saver 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants