Class 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 Detail

      • INTERNAL_THREAD_POOL

        public static final ExecutorService INTERNAL_THREAD_POOL
    • Method Detail

      • startTransactionAsync

        public CompletableFuture<TransactionContext> 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
      • endTransactionAsync

        public CompletableFuture<Void> 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
      • 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
      • 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 namespace
        clientSettings - 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 by createFromNamespaceEndpointURIAsync(URI, ClientSettings)
        Creates a messaging factory instance from namesapce endpoint URI and client settings
        Parameters:
        namespaceEndpointURI - Endpoint URI of the namespace
        clientSettings - 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 namespace
        clientSettings - clientsettings for the factory
        Returns:
        a completablefuture whose result is messagingfactory instance when its execution completes
      • 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 namespace
        clientSettings - clientsettings for the factory
        Returns:
        an instance of MessagingFactory
        Throws:
        InterruptedException - if blocking thread is interrupted
        ServiceBusException - 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 CompletableFuture which 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 CompletableFuture which completes when a connection is established to the namespace or when a connection couldn't be established.
        See Also:
        CompletableFuture
      • 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 interrupted
        ExecutionException - if a connection couldn't be established to the namespace. Cause of the failure can be found by calling Throwable.getCause()
      • onConnectionOpen

        public void onConnectionOpen()
        Internal method. Clients should not use this method.
        Specified by:
        onConnectionOpen in interface IAmqpConnection
      • onConnectionError

        public void onConnectionError​(org.apache.qpid.proton.amqp.transport.ErrorCondition error)
        Internal method. Clients should not use this method.
        Specified by:
        onConnectionError in interface IAmqpConnection
      • registerForConnectionError

        public void registerForConnectionError​(org.apache.qpid.proton.engine.Link link)
        Internal method. Clients should not use this method.
        Specified by:
        registerForConnectionError in interface IAmqpConnection
      • deregisterForConnectionError

        public void deregisterForConnectionError​(org.apache.qpid.proton.engine.Link link)
        Internal method. Clients should not use this method.
        Specified by:
        deregisterForConnectionError in interface IAmqpConnection