MessagingFactory Class

  • java.lang.Object
    • ClientEntity
      • com.microsoft.azure.servicebus.primitives.MessagingFactory

public class MessagingFactory extends ClientEntity

Abstracts all AMQP related details and encapsulates an AMQP connection and manages its life cycle. Each instance of this class represent one AMQP connection to the namespace. If an application creates multiple senders, receivers or clients using the same MessagingFactory instance, all those senders, receivers or clients will share the same connection to the namespace.

Field Summary

Modifier and Type Field and Description
final ExecutorService INTERNAL_THREAD_POOL

Method Summary

Modifier and Type Method and Description
MessagingFactory createFromConnectionString(final String connectionString)

Creates an instance of MessagingFactory from the given connection string. This method blocks for a connection to the namespace to be established.

CompletableFuture<MessagingFactory> createFromConnectionStringAsync(final String connectionString)

Creates an instance of MessagingFactory from the given connection string. This is a non-blocking method.

MessagingFactory createFromConnectionStringBuilder(final ConnectionStringBuilder builder)

Creates an instance of MessagingFactory from the given connection string builder. This method blocks for a connection to the namespace to be established.

CompletableFuture<MessagingFactory> createFromConnectionStringBuilderAsync(final ConnectionStringBuilder builder)

Creates an instance of MessagingFactory from the given connection string builder. This is a non-blocking method.

MessagingFactory createFromNamespaceEndpointURI(URI namespaceEndpointURI, ClientSettings clientSettings)
CompletableFuture<MessagingFactory> createFromNamespaceEndpointURIAsyc(URI namespaceEndpointURI, ClientSettings clientSettings)
MessagingFactory createFromNamespaceName(String sbNamespaceName, ClientSettings clientSettings)
CompletableFuture<MessagingFactory> createFromNamespaceNameAsyc(String sbNamespaceName, ClientSettings clientSettings)
void deregisterForConnectionError(Link link)

Internal method.Clients should not use this method.

void endTransaction(TransactionContext transaction, boolean commit)

Ends a transaction that was initiated using startTransactionAsync().

CompletableFuture<Void> endTransactionAsync(TransactionContext transaction, boolean commit)

Ends a transaction that was initiated using startTransactionAsync().

ClientSettings getClientSettings()
String getHostName()
Duration getOperationTimeout()

Gets the operation timeout from the connections string.

RetryPolicy getRetryPolicy()

Gets the retry policy from the connection string.

CompletableFuture<Void> onClose()
void onConnectionError(ErrorCondition error)

Internal method.Clients should not use this method.

void onConnectionOpen()

Internal method.Clients should not use this method.

void registerForConnectionError(Link link)

Internal method.Clients should not use this method.

TransactionContext startTransaction()

Starts a new service side transaction. The TransactionContext should be passed to all operations that needs to be in this transaction.

CompletableFuture<TransactionContext> startTransactionAsync()

Starts a new service side transaction. The TransactionContext should be passed to all operations that needs to be in this transaction.

Inherited Members

Field Details

INTERNAL_THREAD_POOL

public static final ExecutorService INTERNAL_THREAD_POOL= Executors.newCachedThreadPool()

Method Details

createFromConnectionString

public static MessagingFactory createFromConnectionString(final String connectionString)

Creates an instance of MessagingFactory from the given connection string. This method blocks for a connection to the namespace to be established.

Parameters:

connectionString - connection string to the bus namespace or entity

Returns:

an instance of MessagingFactory

Throws:

InterruptedException - if blocking thread is interrupted
ExecutionException - if a connection couldn't be established to the namespace. Cause of the failure can be found by calling Exception#getCause()

createFromConnectionStringAsync

public static CompletableFuture createFromConnectionStringAsync(final String connectionString)

Creates an instance of MessagingFactory from the given connection string. This is a non-blocking method.

Parameters:

connectionString - connection string to the bus namespace or entity

Returns:

a CompletableFuture which completes when a connection is established to the namespace or when a connection couldn't be established.

createFromConnectionStringBuilder

public static MessagingFactory createFromConnectionStringBuilder(final ConnectionStringBuilder builder)

Creates an instance of MessagingFactory from the given connection string builder. This method blocks for a connection to the namespace to be established.

Parameters:

builder - connection string builder to the bus namespace or entity

Returns:

an instance of MessagingFactory

Throws:

InterruptedException - if blocking thread is interrupted
ExecutionException - if a connection couldn't be established to the namespace. Cause of the failure can be found by calling Exception#getCause()

createFromConnectionStringBuilderAsync

public static CompletableFuture createFromConnectionStringBuilderAsync(final ConnectionStringBuilder builder)

Creates an instance of MessagingFactory from the given connection string builder. This is a non-blocking method.

Parameters:

builder - connection string builder to the bus namespace or entity

Returns:

a CompletableFuture which completes when a connection is established to the namespace or when a connection couldn't be established.

createFromNamespaceEndpointURI

public static MessagingFactory createFromNamespaceEndpointURI(URI namespaceEndpointURI, ClientSettings clientSettings)

Parameters:

namespaceEndpointURI
clientSettings

createFromNamespaceEndpointURIAsyc

public static CompletableFuture createFromNamespaceEndpointURIAsyc(URI namespaceEndpointURI, ClientSettings clientSettings)

Parameters:

namespaceEndpointURI
clientSettings

createFromNamespaceName

public static MessagingFactory createFromNamespaceName(String sbNamespaceName, ClientSettings clientSettings)

Parameters:

sbNamespaceName
clientSettings

createFromNamespaceNameAsyc

public static CompletableFuture createFromNamespaceNameAsyc(String sbNamespaceName, ClientSettings clientSettings)

Parameters:

sbNamespaceName
clientSettings

deregisterForConnectionError

public void deregisterForConnectionError(Link link)

Internal method.Clients should not use this method.

Parameters:

link

endTransaction

public void endTransaction(TransactionContext transaction, boolean commit)

Ends a transaction that was initiated using startTransactionAsync().

Parameters:

transaction - The transaction object.
commit - A boolean value of true indicates transaction to be committed. A value of false indicates a transaction rollback.

Throws:

ServiceBusException - if transaction fails to end
InterruptedException - if the current thread was interrupted while waiting

endTransactionAsync

public CompletableFuture endTransactionAsync(TransactionContext transaction, boolean commit)

Ends a transaction that was initiated using startTransactionAsync().

Parameters:

transaction - The transaction object.
commit - A boolean value of true indicates transaction to be committed. A value of false indicates a transaction rollback.

Returns:

A CompletableFuture

getClientSettings

public ClientSettings getClientSettings()

getHostName

public String getHostName()

getOperationTimeout

public Duration getOperationTimeout()

Gets the operation timeout from the connections string.

Returns:

operation timeout specified in the connection string

getRetryPolicy

public RetryPolicy getRetryPolicy()

Gets the retry policy from the connection string.

Returns:

retry policy specified in the connection string

onClose

protected CompletableFuture onClose()

onConnectionError

public void onConnectionError(ErrorCondition error)

Internal method.Clients should not use this method.

Parameters:

error

onConnectionOpen

public void onConnectionOpen()

Internal method.Clients should not use this method.

registerForConnectionError

public void registerForConnectionError(Link link)

Internal method.Clients should not use this method.

Parameters:

link

startTransaction

public TransactionContext startTransaction()

Starts a new service side transaction. The TransactionContext should be passed to all operations that needs to be in this transaction.

Returns:

a new transaction

Throws:

ServiceBusException - if transaction fails to start
InterruptedException - if the current thread was interrupted while waiting

startTransactionAsync

public CompletableFuture startTransactionAsync()

Starts a new service side transaction. The TransactionContext should be passed to all operations that needs to be in this transaction.

Returns:

A CompletableFuture which returns a new transaction

Applies to