Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

GH-212: Add ConsumerSeekAware impl to Inbounds #213

Merged
merged 4 commits into from
Sep 7, 2018

Conversation

artembilan
Copy link
Contributor

Fixes #212

Cherry-pick to 3.0.x

@artembilan artembilan changed the title GH-212: Add ConsumerSeekAware impl to Inbounds [DO NOT MERGE YET] GH-212: Add ConsumerSeekAware impl to Inbounds Sep 6, 2018
@artembilan
Copy link
Contributor Author

Do not merge yet: the proposed solution is slightly useless.
I believe we need to introduce a new header for the message to send. This is exactly what is a custom listener code - Spring Integration flow.

Stay tuned!

Fixes spring-attic#212

* Introduce a new `IntegrationKafkaHeaders.CONSUMER_SEEK_CALLBACK`
header to be populated to messages for sending to the channel
* Populate that header from the `KafkaInboundGateway` and
`KafkaMessageDrivenChannelAdapter` into the message from the
`seekCallBack` property if `ListenerContainer` is single-threaded or
from the `ThreadLocal<ConsumerSeekAware.ConsumerSeekCallback>` otherwise;
and only if newly introduced `setAdditionalHeaders` is `true`
* Populate `seekCallBack` property or `ThreadLocal<?>` from the
`registerSeekCallback()` implementation from the internal listeners
* Add `setOnPartitionsAssignedSeekCallback(BiConsumer)` and
`setOnIdleSeekCallback(BiConsumer)` options to react for the appropriate
event from the underlying container and perform appropriate seek management
* Add new options to the DSL classes and cover them with tests, including
check for new `IntegrationKafkaHeaders.CONSUMER_SEEK_CALLBACK` header

**Cherry-pick to 3.0.x**
@artembilan artembilan changed the title [DO NOT MERGE YET] GH-212: Add ConsumerSeekAware impl to Inbounds GH-212: Add ConsumerSeekAware impl to Inbounds Sep 6, 2018
@artembilan
Copy link
Contributor Author

Ready for review.
Thanks

Copy link
Contributor

@garyrussell garyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only need the onPartitionsAssigned code to allow an initial seek at that time; the Consumer is provided in a header so they can seek on it directly. Also, as long as they use the normal event multicaster, they can seek from an event listener for the idle event.

this.seekCallback = callback;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need this extra complexity - why not always use the ThreadLocal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's not end-user API, so I don't see reason to worry about complexity in our code since with the single-threaded container we will avoid ThreadLocal overhead altogether.

* @since 3.0.4
* @see IntegrationKafkaHeaders
*/
public void setAdditionalRequestHeaders(boolean setAdditionalHeaders) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name seems too general; it is specifically related to adding the seek callback to the headers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for now. I'm open for better name.
Or do you think it would be better to add a boolean setter for any new headers which may come in the future?

@garyrussell
Copy link
Contributor

Did you see my general review comment?

@artembilan
Copy link
Contributor Author

Good point about ListenerContainerIdleEvent!
I will remove the idleCallback option.

What else should I pay attention in your review?
Looks like I've answered to all comments.

Thanks

@garyrussell
Copy link
Contributor

I mean I don't think we need to add the callback as a header, since the Consumer is already there as one.

@artembilan
Copy link
Contributor Author

Huh? So, we don't need registerSeekCallback(ConsumerSeekCallback callback) now at all?

I'll fix all your concern. And having the argument about Consumer header, I don't see a value in the ThreadLocal discussion. That code is just going to disappear!

@garyrussell
Copy link
Contributor

Indeed 😄

Copy link
Contributor

@garyrussell garyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's all.

KafkaInboundGateway.this.onPartitionsAssignedSeekCallback.accept(assignments, callback);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only from the record listener?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh? There is no IntegrationBatchMessageListener in the gateway.

Sorry, I'm not sure how to proceed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On other thought the batch processing does not make sense in the request-reply scenarios.
So, that's fully fine that we don't support batch there.

Please, elaborate with your concern.

Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh; sorry; you are correct; I guess I was confused by the Javadocs iin the MDCA (which is wrong).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Will fix that JavaDoc in a few.

* Specify a {@link BiConsumer} for seeks management during
* {@link ConsumerSeekAware.ConsumerSeekCallback#onPartitionsAssigned(Map, ConsumerSeekAware.ConsumerSeekCallback)}
* call from the {@link org.springframework.kafka.listener.KafkaMessageListenerContainer}.
* This is called from the internal {@link RecordMessagingMessageListenerAdapter} implementation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, it's called from both.

*Close producers in the `KafkaProducerMessageHandlerTests`
@garyrussell garyrussell merged commit 29bb8c2 into spring-attic:master Sep 7, 2018
garyrussell pushed a commit that referenced this pull request Sep 7, 2018
* GH-212: Add ConsumerSeekAware impl to Inbounds

Fixes #212

**Cherry-pick to 3.0.x**

* GH-212: Add ConsumerSeekAware impl to Inbounds

Fixes #212

* Introduce a new `IntegrationKafkaHeaders.CONSUMER_SEEK_CALLBACK`
header to be populated to messages for sending to the channel
* Populate that header from the `KafkaInboundGateway` and
`KafkaMessageDrivenChannelAdapter` into the message from the
`seekCallBack` property if `ListenerContainer` is single-threaded or
from the `ThreadLocal<ConsumerSeekAware.ConsumerSeekCallback>` otherwise;
and only if newly introduced `setAdditionalHeaders` is `true`
* Populate `seekCallBack` property or `ThreadLocal<?>` from the
`registerSeekCallback()` implementation from the internal listeners
* Add `setOnPartitionsAssignedSeekCallback(BiConsumer)` and
`setOnIdleSeekCallback(BiConsumer)` options to react for the appropriate
event from the underlying container and perform appropriate seek management
* Add new options to the DSL classes and cover them with tests, including
check for new `IntegrationKafkaHeaders.CONSUMER_SEEK_CALLBACK` header

**Cherry-pick to 3.0.x**

* Address PR comments: remove unnecessary API

* *Polishing `setOnPartitionsAssignedSeekCallback()` JavaDocs
*Close producers in the `KafkaProducerMessageHandlerTests`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants