Skip to content

Fix listener TaskExecutor config #1104

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public C createRegisteredContainer(PulsarListenerEndpoint endpoint) {

endpoint.setupListenerContainer(instance, this.messageConverter);
initializeContainer(instance, endpoint);
// customizeContainer(instance);
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @author Chris Bono
* @author Alexander Preuß
* @author Vedran Pavic
* @author Daniel Szabo
*/
public class ConcurrentPulsarListenerContainerFactory<T>
extends AbstractPulsarListenerContainerFactory<ConcurrentPulsarMessageListenerContainer<T>, T> {
Expand Down Expand Up @@ -80,6 +81,7 @@ protected ConcurrentPulsarMessageListenerContainer<T> createContainerInstance(Pu
var containerProps = new PulsarContainerProperties();

// Map factory props (defaults) to the container props
containerProps.setConsumerTaskExecutor(factoryProps.getConsumerTaskExecutor());
Copy link
Author

Choose a reason for hiding this comment

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

I didn't do the null check mentioned in the issue comment because this will always be a new instance. Most other options also assume we just want to set the factory values.

containerProps.setSchemaResolver(factoryProps.getSchemaResolver());
containerProps.setTopicResolver(factoryProps.getTopicResolver());
containerProps.setSubscriptionType(factoryProps.getSubscriptionType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.pulsar.core.PulsarConsumerFactory;
import org.springframework.pulsar.listener.PulsarContainerProperties;

Expand Down Expand Up @@ -142,4 +143,26 @@ void defaultUsedWhenNotSetOnEndpointNorFactoryProps() {

}

@Nested
class ConsumerTaskExecutor {

@Test
@SuppressWarnings("unchecked")
void factoryValueCopiedWhenCreatingContainer() {
final var factoryProps = new PulsarContainerProperties();
factoryProps.setConsumerTaskExecutor(new SimpleAsyncTaskExecutor());
final var containerFactory = new ConcurrentPulsarListenerContainerFactory<String>(
mock(PulsarConsumerFactory.class), factoryProps);
final var endpoint = mock(PulsarListenerEndpoint.class);
// Mockito by default returns 0 for Integer
when(endpoint.getConcurrency()).thenReturn(null);

final var createdContainer = containerFactory.createRegisteredContainer(endpoint);

final var containerProperties = createdContainer.getContainerProperties();
assertThat(containerProperties.getConsumerTaskExecutor()).isEqualTo(factoryProps.getConsumerTaskExecutor());
}

}

}