-
Notifications
You must be signed in to change notification settings - Fork 692
Adding original message to the throwble for Pub/Sub publish failures. #2020
Conversation
@sateekot Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@sateekot Thank you for signing the Contributor License Agreement! |
Codecov Report
@@ Coverage Diff @@
## master #2020 +/- ##
============================================
- Coverage 80.44% 72.48% -7.96%
+ Complexity 2120 1885 -235
============================================
Files 243 244 +1
Lines 6907 6913 +6
Branches 710 710
============================================
- Hits 5556 5011 -545
- Misses 1056 1574 +518
- Partials 295 328 +33
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for putting together the PR!
I just have one suggested change.
BTW this is for #2003
@@ -103,7 +106,10 @@ public void setMessageConverter(PubSubMessageConverter pubSubMessageConverter) { | |||
@Override | |||
public void onFailure(Throwable throwable) { | |||
LOGGER.warn("Publishing to " + topic + " topic failed.", throwable); | |||
settableFuture.setException(throwable); | |||
Message<?> originalMessage = MessageBuilder.withPayload(pubsubMessage).build(); | |||
MessageHandlingException messageHandlingException = new MessageHandlingException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use MessageDeliveryException
instead please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I wouldn't do that.
I mean we are good to have a PubSubDeliveryException
as an extension of the PubSubException
.
My point is to not wrap a PubsubMessage
into a Message<?>
: an original request is not Spring Messaging.
So, let's not abuse non-related API, but we definitely can borrow an idea! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comments. I have updated the code accordingly. Can you please check the updated commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your name, please, into the modified classes.
And let's consider to mention such a feature in docs somehow!
Thanks
@@ -103,7 +106,10 @@ public void setMessageConverter(PubSubMessageConverter pubSubMessageConverter) { | |||
@Override | |||
public void onFailure(Throwable throwable) { | |||
LOGGER.warn("Publishing to " + topic + " topic failed.", throwable); | |||
settableFuture.setException(throwable); | |||
Message<?> originalMessage = MessageBuilder.withPayload(pubsubMessage).build(); | |||
MessageHandlingException messageHandlingException = new MessageHandlingException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I wouldn't do that.
I mean we are good to have a PubSubDeliveryException
as an extension of the PubSubException
.
My point is to not wrap a PubsubMessage
into a Message<?>
: an original request is not Spring Messaging.
So, let's not abuse non-related API, but we definitely can borrow an idea! 😄
@artembilan I am not sure how to update this feature in docs, Can you please give me some pointers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs could be updated in pubsub.adoc. If you don't feel comfortable doing it, it's ok to create an issue to do it in a separate PR.
this.failedMessage = pubsubMessage; | ||
} | ||
|
||
public PubSubDeliveryException(PubsubMessage pubsubMessage, Throwable cause) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just keep the one constructor we currently use. We can always add more. Otherwise, we have all this code that's missing coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed constructors.
} | ||
|
||
@Override | ||
public String toString() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't typically overwrite the toString()
for exceptions. Who is going to call this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't override toString(), the newly added test case is failing as we are checking the message in the exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That has to be done with the cast and that getFailedMessage()
.
So, yes +1 to remove this toString()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is some review from me.
Nothing critical - a general solution is OK.
} | ||
|
||
@Override | ||
public String toString() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That has to be done with the cast and that getFailedMessage()
.
So, yes +1 to remove this toString()
private final PubsubMessage failedMessage; | ||
|
||
public PubSubDeliveryException(PubsubMessage pubsubMessage, Throwable cause) { | ||
super(null, cause); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to provide some message into an exception anyway.
I mean that required by super class description.
therefore one more ctor arg in this PubSubDeliveryException
public void testPublish_onFailureWithPayload() { | ||
ListenableFuture<String> future = this.pubSubTemplate.publish("testTopic", this.pubsubMessage); | ||
this.settableApiFuture.setException(new Exception("Publish failed")); | ||
assertThatThrownBy(() -> future.get()).isInstanceOf(ExecutionException.class).hasMessageContaining("permanating") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to check in the test that we have already that new PubSubDeliveryException
with expected this.pubsubMessage
populated. I believe that was a main goal of this fix.
@@ -103,7 +105,8 @@ public void setMessageConverter(PubSubMessageConverter pubSubMessageConverter) { | |||
@Override | |||
public void onFailure(Throwable throwable) { | |||
LOGGER.warn("Publishing to " + topic + " topic failed.", throwable); | |||
settableFuture.setException(throwable); | |||
PubSubDeliveryException pubSubDeliveryException = new PubSubDeliveryException(pubsubMessage, throwable.getMessage(), throwable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't want to see the same throwable.getMessage()
here again on top of stack trace.
I can get it in the stack trace anyway parsing a cause
.
What I want to see is an explicit message indicating that exactly here in the PubSubTemplate
we couldn't delivered a message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
I think what you're logging should work here as well for the message:
"Publishing to " + topic + " topic failed."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code.
@@ -103,7 +105,8 @@ public void setMessageConverter(PubSubMessageConverter pubSubMessageConverter) { | |||
@Override | |||
public void onFailure(Throwable throwable) { | |||
LOGGER.warn("Publishing to " + topic + " topic failed.", throwable); | |||
settableFuture.setException(throwable); | |||
PubSubDeliveryException pubSubDeliveryException = new PubSubDeliveryException(pubsubMessage, throwable.getMessage(), throwable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
I think what you're logging should work here as well for the message:
"Publishing to " + topic + " topic failed."
Adding original message to Future provided by Publisher if any failures to publish events to Pub/Sub.