Skip to content

Add support for configuring Pulsar client IO and listener threads #42052

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

Closed
Closed
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 @@ -44,6 +44,7 @@
* @author Chris Bono
* @author Phillip Webb
* @author Swamy Mavuri
* @author Vedran Pavic
* @since 3.2.0
*/
@ConfigurationProperties("spring.pulsar")
Expand Down Expand Up @@ -136,6 +137,11 @@ public static class Client {
*/
private final Authentication authentication = new Authentication();

/**
* Thread related configuration.
*/
private final Threads threads = new Threads();

/**
* Failover settings.
*/
Expand Down Expand Up @@ -177,6 +183,10 @@ public Authentication getAuthentication() {
return this.authentication;
}

public Threads getThreads() {
return this.threads;
}

public Failover getFailover() {
return this.failover;
}
Expand Down Expand Up @@ -959,6 +969,36 @@ public void setParam(Map<String, String> param) {

}

public static class Threads {

/**
* Number of threads to be used for handling connections to brokers.
*/
private Integer io;

/**
* Number of threads to be used for message listeners.
*/
private Integer listener;

public Integer getIo() {
return this.io;
}

public void setIo(Integer io) {
this.io = io;
}

public Integer getListener() {
return this.listener;
}

public void setListener(Integer listener) {
this.listener = listener;
}

}

public static class Failover {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
* @author Chris Bono
* @author Phillip Webb
* @author Swamy Mavuri
* @author Vedran Pavic
*/
final class PulsarPropertiesMapper {

Expand All @@ -68,6 +69,8 @@ void customizeClientBuilder(ClientBuilder clientBuilder, PulsarConnectionDetails
map.from(properties::getConnectionTimeout).to(timeoutProperty(clientBuilder::connectionTimeout));
map.from(properties::getOperationTimeout).to(timeoutProperty(clientBuilder::operationTimeout));
map.from(properties::getLookupTimeout).to(timeoutProperty(clientBuilder::lookupTimeout));
map.from(properties.getThreads()::getIo).to(clientBuilder::ioThreads);
map.from(properties.getThreads()::getListener).to(clientBuilder::listenerThreads);
map.from(this.properties.getTransaction()::isEnabled).whenTrue().to(clientBuilder::enableTransaction);
customizeAuthentication(properties.getAuthentication(), clientBuilder::authentication);
customizeServiceUrlProviderBuilder(clientBuilder::serviceUrl, clientBuilder::serviceUrlProvider, properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* @author Chris Bono
* @author Phillip Webb
* @author Swamy Mavuri
* @author Vedran Pavic
*/
class PulsarPropertiesMapperTests {

Expand All @@ -69,13 +70,17 @@ void customizeClientBuilderWhenHasNoAuthentication() {
properties.getClient().setConnectionTimeout(Duration.ofSeconds(1));
properties.getClient().setOperationTimeout(Duration.ofSeconds(2));
properties.getClient().setLookupTimeout(Duration.ofSeconds(3));
properties.getClient().getThreads().setIo(3);
properties.getClient().getThreads().setListener(10);
ClientBuilder builder = mock(ClientBuilder.class);
new PulsarPropertiesMapper(properties).customizeClientBuilder(builder,
new PropertiesPulsarConnectionDetails(properties));
then(builder).should().serviceUrl("https://example.com");
then(builder).should().connectionTimeout(1000, TimeUnit.MILLISECONDS);
then(builder).should().operationTimeout(2000, TimeUnit.MILLISECONDS);
then(builder).should().lookupTimeout(3000, TimeUnit.MILLISECONDS);
then(builder).should().ioThreads(3);
then(builder).should().listenerThreads(10);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* @author Soby Chacko
* @author Phillip Webb
* @author Swamy Mavuri
* @author Vedran Pavic
*/
class PulsarPropertiesTests {

Expand Down Expand Up @@ -88,6 +89,16 @@ void bindAuthentication() {
assertThat(properties.getAuthentication().getParam()).containsEntry("token", "1234");
}

@Test
void bindThread() {
Map<String, String> map = new HashMap<>();
map.put("spring.pulsar.client.threads.io", "3");
map.put("spring.pulsar.client.threads.listener", "10");
PulsarProperties.Client properties = bindProperties(map).getClient();
assertThat(properties.getThreads().getIo()).isEqualTo(3);
assertThat(properties.getThreads().getListener()).isEqualTo(10);
}

@Test
void bindFailover() {
Map<String, String> map = new HashMap<>();
Expand Down