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

Builder for Rest Client of remote-transactions #213

Open
martinaubele opened this issue Jun 14, 2024 · 0 comments
Open

Builder for Rest Client of remote-transactions #213

martinaubele opened this issue Jun 14, 2024 · 0 comments

Comments

@martinaubele
Copy link

martinaubele commented Jun 14, 2024

At the moment the REST client for remote-transactions is created inside ParticipantAdapter. It is hard coded to use javax.ws.rs.client.ClientBuilder.

We observed severe performance problems because the Jaxrs default client does not offer a proper http connection handling.

To allow customization we propose to introduce a Builder Pattern:

RestClientBuilder is a new abstract class that is extended by DefaultRestClientBuilder. This one creates the REST Client in the same way as before.
You can extend RestClientBuild by your own implementation and define it in the new property com.atomikos.remoting.rest_client_builder.

com.atomikos.remoting.rest_client_builder=MyRestClientBuilderWithHttpCommonsConnectionPooling

Here is an example for REST Client with Http Connection Pooling

public class PooledRestClientBuilder extends RestClientBuilder {

	@Override
	public Client build() {
		ResteasyClientBuilder builder = new ResteasyClientBuilder();
		
		ConfigProperties configProperties = Configuration.getConfigProperties();
		String connectionPoolSizeProperty = configProperties.getProperty("com.atomikos.remoting.twopc.ParticipantAdapter.connectionPoolSize");
		int connectionPoolSize = 20;
		if (connectionPoolSizeProperty != null)
			connectionPoolSize = Integer.valueOf(connectionPoolSizeProperty);
		
		String connectTimeoutProperty = configProperties.getProperty("com.atomikos.remoting.twopc.ParticipantAdapter.connectTimeout");
		int connectTimeout = 10;
		if (connectTimeoutProperty != null)
			connectTimeout = Integer.valueOf(connectTimeoutProperty);

		String readTimeoutProperty = configProperties.getProperty("com.atomikos.remoting.twopc.ParticipantAdapter.readTimeout");
		int readTimeout = 60;
		if (readTimeoutProperty != null)
			readTimeout = Integer.valueOf(readTimeoutProperty);

		builder.connectTimeout(connectTimeout, TimeUnit.SECONDS);
		builder.readTimeout(readTimeout, TimeUnit.SECONDS);
		Client c = builder.connectionPoolSize(connectionPoolSize).build(); 
		c.property("jersey.config.client.suppressHttpComplianceValidation", true);
		c.register(ParticipantsProvider.class);
		return c;
	}
}

IMPORTANT: To allow connection pooling it has to be ensured that the content of each response is consumed. Therefore we had the change some code in ParticipantAdapter.

Pull request: #214

@martinaubele martinaubele changed the title Builder for Rest Client for remote-transactions Builder for Rest Client of remote-transactions Jun 14, 2024
martinaubele added a commit to martinaubele/transactions-essentials that referenced this issue Jun 14, 2024
Builder for Rest Client of remote-transactions
martinaubele added a commit to martinaubele/transactions-essentials that referenced this issue Jun 17, 2024
Builder for Rest Client of remote-transactions
aubelix pushed a commit to aubelix/transactions-essentials that referenced this issue Jul 6, 2024
Builder for Rest Client of remote-transactions. Backport von Version 6
auf Version 5
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

1 participant