Class MessagingFactory
- java.lang.Object
-
- com.microsoft.azure.servicebus.primitives.ClientEntity
-
- com.microsoft.azure.servicebus.primitives.MessagingFactory
-
- All Implemented Interfaces:
IAmqpConnection
public class MessagingFactory extends ClientEntity implements IAmqpConnection
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.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static ExecutorServiceINTERNAL_THREAD_POOL
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static MessagingFactorycreateFromConnectionString(String connectionString)Creates an instance of MessagingFactory from the given connection string.static CompletableFuture<MessagingFactory>createFromConnectionStringAsync(String connectionString)Creates an instance of MessagingFactory from the given connection string.static MessagingFactorycreateFromConnectionStringBuilder(ConnectionStringBuilder builder)Creates an instance of MessagingFactory from the given connection string builder.static CompletableFuture<MessagingFactory>createFromConnectionStringBuilderAsync(ConnectionStringBuilder builder)Creates an instance of MessagingFactory from the given connection string builder.static MessagingFactorycreateFromNamespaceEndpointURI(URI namespaceEndpointURI, ClientSettings clientSettings)Creates a messaging factory instance from namesapce endpoint URI and client settingsstatic CompletableFuture<MessagingFactory>createFromNamespaceEndpointURIAsyc(URI namespaceEndpointURI, ClientSettings clientSettings)Deprecated.Deprecating as spelling is wrong.static CompletableFuture<MessagingFactory>createFromNamespaceEndpointURIAsync(URI namespaceEndpointURI, ClientSettings clientSettings)Creates a messaging factory instance from namesapce endpoint URI and client settingsstatic MessagingFactorycreateFromNamespaceName(String sbNamespaceName, ClientSettings clientSettings)Creates a messaging factory instance from namesapce name and client settingsstatic CompletableFuture<MessagingFactory>createFromNamespaceNameAsyc(String sbNamespaceName, ClientSettings clientSettings)Deprecated.Deprecating as spelling is wrong.static CompletableFuture<MessagingFactory>createFromNamespaceNameAsync(String sbNamespaceName, ClientSettings clientSettings)Creates a messaging factory instance from namesapce name and client settingsvoidderegisterForConnectionError(org.apache.qpid.proton.engine.Link link)Internal method. Clients should not use this method.voidendTransaction(TransactionContext transaction, boolean commit)Ends a transaction that was initiated usingstartTransactionAsync().CompletableFuture<Void>endTransactionAsync(TransactionContext transaction, boolean commit)Ends a transaction that was initiated usingstartTransactionAsync().ClientSettingsgetClientSettings()Gets client settings for this messaging factory instanceStringgetHostName()DurationgetOperationTimeout()Gets the operation timeout from the connections string.RetryPolicygetRetryPolicy()Gets the retry policy from the connection string.protected CompletableFuture<Void>onClose()voidonConnectionError(org.apache.qpid.proton.amqp.transport.ErrorCondition error)Internal method. Clients should not use this method.voidonConnectionOpen()Internal method. Clients should not use this method.voidregisterForConnectionError(org.apache.qpid.proton.engine.Link link)Internal method. Clients should not use this method.TransactionContextstartTransaction()Starts a new service side transaction.CompletableFuture<TransactionContext>startTransactionAsync()Starts a new service side transaction.-
Methods inherited from class com.microsoft.azure.servicebus.primitives.ClientEntity
close, closeAsync, finalize, getClientId, getIsClosed, getIsClosingOrClosed, setClosed, setClosing, throwIfClosed
-
-
-
-
Field Detail
-
INTERNAL_THREAD_POOL
public static final ExecutorService INTERNAL_THREAD_POOL
-
-
Method Detail
-
startTransaction
public TransactionContext startTransaction() throws ServiceBusException, InterruptedException
Starts a new service side transaction. TheTransactionContextshould be passed to all operations that needs to be in this transaction.- Returns:
- a new transaction
- Throws:
ServiceBusException- if transaction fails to startInterruptedException- if the current thread was interrupted while waiting
-
startTransactionAsync
public CompletableFuture<TransactionContext> startTransactionAsync()
Starts a new service side transaction. TheTransactionContextshould be passed to all operations that needs to be in this transaction.- Returns:
- A
CompletableFuturewhich returns a new transaction
-
endTransaction
public void endTransaction(TransactionContext transaction, boolean commit) throws ServiceBusException, InterruptedException
Ends a transaction that was initiated usingstartTransactionAsync().- Parameters:
transaction- The transaction object.commit- A boolean value oftrueindicates transaction to be committed. A value offalseindicates a transaction rollback.- Throws:
ServiceBusException- if transaction fails to endInterruptedException- if the current thread was interrupted while waiting
-
endTransactionAsync
public CompletableFuture<Void> endTransactionAsync(TransactionContext transaction, boolean commit)
Ends a transaction that was initiated usingstartTransactionAsync().- Parameters:
transaction- The transaction object.commit- A boolean value oftrueindicates transaction to be committed. A value offalseindicates a transaction rollback.- Returns:
- A
CompletableFuture
-
getHostName
public String getHostName()
- Specified by:
getHostNamein interfaceIAmqpConnection
-
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
-
getClientSettings
public ClientSettings getClientSettings()
Gets client settings for this messaging factory instance- Returns:
- client settings for this messaging factory instance
-
createFromNamespaceNameAsyc
@Deprecated public static CompletableFuture<MessagingFactory> createFromNamespaceNameAsyc(String sbNamespaceName, ClientSettings clientSettings)
Deprecated.Deprecating as spelling is wrong. Replaced bycreateFromNamespaceNameAsync(String, ClientSettings)Creates a messaging factory instance from namesapce name and client settings- Parameters:
sbNamespaceName- name of the namespaceclientSettings- clientsettings for the factory- Returns:
- a completablefuture whose result is messagingfactory instance when its execution completes
-
createFromNamespaceNameAsync
public static CompletableFuture<MessagingFactory> createFromNamespaceNameAsync(String sbNamespaceName, ClientSettings clientSettings)
Creates a messaging factory instance from namesapce name and client settings- Parameters:
sbNamespaceName- name of the namespaceclientSettings- clientsettings for the factory- Returns:
- a completablefuture whose result is messagingfactory instance when its execution completes
-
createFromNamespaceEndpointURIAsyc
@Deprecated public static CompletableFuture<MessagingFactory> createFromNamespaceEndpointURIAsyc(URI namespaceEndpointURI, ClientSettings clientSettings)
Deprecated.Deprecating as spelling is wrong. Replaced bycreateFromNamespaceEndpointURIAsync(URI, ClientSettings)Creates a messaging factory instance from namesapce endpoint URI and client settings- Parameters:
namespaceEndpointURI- Endpoint URI of the namespaceclientSettings- clientsettings for the factory- Returns:
- a completablefuture whose result is messagingfactory instance when its execution completes
-
createFromNamespaceEndpointURIAsync
public static CompletableFuture<MessagingFactory> createFromNamespaceEndpointURIAsync(URI namespaceEndpointURI, ClientSettings clientSettings)
Creates a messaging factory instance from namesapce endpoint URI and client settings- Parameters:
namespaceEndpointURI- Endpoint URI of the namespaceclientSettings- clientsettings for the factory- Returns:
- a completablefuture whose result is messagingfactory instance when its execution completes
-
createFromNamespaceName
public static MessagingFactory createFromNamespaceName(String sbNamespaceName, ClientSettings clientSettings) throws InterruptedException, ServiceBusException
Creates a messaging factory instance from namesapce name and client settings- Parameters:
sbNamespaceName- name of the namespaceclientSettings- clientsettings for the factory- Returns:
- an instance of MessagingFactory
- Throws:
InterruptedException- if blocking thread is interruptedServiceBusException- if a connection couldn't be established to the namespace
-
createFromNamespaceEndpointURI
public static MessagingFactory createFromNamespaceEndpointURI(URI namespaceEndpointURI, ClientSettings clientSettings) throws InterruptedException, ServiceBusException
Creates a messaging factory instance from namesapce endpoint URI and client settings- Parameters:
namespaceEndpointURI- Endpoint URI of the namespaceclientSettings- clientsettings for the factory- Returns:
- an instance of MessagingFactory
- Throws:
InterruptedException- if blocking thread is interruptedServiceBusException- if a connection couldn't be established to the namespace
-
createFromConnectionStringBuilderAsync
public static CompletableFuture<MessagingFactory> createFromConnectionStringBuilderAsync(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
CompletableFuturewhich completes when a connection is established to the namespace or when a connection couldn't be established. - See Also:
CompletableFuture
-
createFromConnectionStringAsync
public static CompletableFuture<MessagingFactory> createFromConnectionStringAsync(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
CompletableFuturewhich completes when a connection is established to the namespace or when a connection couldn't be established. - See Also:
CompletableFuture
-
createFromConnectionStringBuilder
public static MessagingFactory createFromConnectionStringBuilder(ConnectionStringBuilder builder) throws InterruptedException, ExecutionException
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 interruptedExecutionException- if a connection couldn't be established to the namespace. Cause of the failure can be found by callingThrowable.getCause()
-
createFromConnectionString
public static MessagingFactory createFromConnectionString(String connectionString) throws InterruptedException, ExecutionException
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 interruptedExecutionException- if a connection couldn't be established to the namespace. Cause of the failure can be found by callingThrowable.getCause()
-
onConnectionOpen
public void onConnectionOpen()
Internal method. Clients should not use this method.- Specified by:
onConnectionOpenin interfaceIAmqpConnection
-
onConnectionError
public void onConnectionError(org.apache.qpid.proton.amqp.transport.ErrorCondition error)
Internal method. Clients should not use this method.- Specified by:
onConnectionErrorin interfaceIAmqpConnection
-
onClose
protected CompletableFuture<Void> onClose()
- Specified by:
onClosein classClientEntity
-
registerForConnectionError
public void registerForConnectionError(org.apache.qpid.proton.engine.Link link)
Internal method. Clients should not use this method.- Specified by:
registerForConnectionErrorin interfaceIAmqpConnection
-
deregisterForConnectionError
public void deregisterForConnectionError(org.apache.qpid.proton.engine.Link link)
Internal method. Clients should not use this method.- Specified by:
deregisterForConnectionErrorin interfaceIAmqpConnection
-
-