Esempio n. 1
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="ServiceBusSender"/> class.
 /// </summary>
 ///
 /// <param name="connectionString">The connection string to use for connecting to the Service Bus namespace; it is expected that the shared key properties are contained in this connection string, but not the Service Bus entity name.</param>
 /// <param name="entityName">The name of the specific Service Bus entity to associate the producer with.</param>
 /// <param name="clientOptions">A set of options to apply when configuring the producer.</param>
 ///
 /// <remarks>
 ///   If the connection string is copied from the Service Bus entity itself, it will contain the name of the desired Service Bus entity,
 ///   and can be used directly without passing the <paramref name="entityName" />.  The name of the Service Bus entity should be
 ///   passed only once, either as part of the connection string or separately.
 /// </remarks>
 ///
 public ServiceBusSender(
     string connectionString,
     string entityName,
     ServiceBusSenderClientOptions clientOptions)
 {
     Argument.AssertNotNullOrEmpty(connectionString, nameof(connectionString));
     clientOptions     = clientOptions?.Clone() ?? new ServiceBusSenderClientOptions();
     ClientDiagnostics = new ClientDiagnostics(clientOptions);
     OwnsConnection    = true;
     Connection        = new ServiceBusConnection(connectionString, entityName, clientOptions.ConnectionOptions);
     RetryPolicy       = clientOptions.RetryOptions.ToRetryPolicy();
     InnerSender       = Connection.CreateTransportProducer(RetryPolicy);
 }
Esempio n. 2
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="ServiceBusSender"/> class.
        /// </summary>
        ///
        /// <param name="connection">The <see cref="ServiceBusConnection" /> connection to use for communication with the Service Bus service.</param>
        /// <param name="clientOptions">A set of options to apply when configuring the producer.</param>
        ///
        internal ServiceBusSender(
            ServiceBusConnection connection,
            ServiceBusSenderClientOptions clientOptions = default)
        {
            Argument.AssertNotNull(connection, nameof(connection));
            clientOptions     = clientOptions?.Clone() ?? new ServiceBusSenderClientOptions();
            ClientDiagnostics = new ClientDiagnostics(clientOptions);

            OwnsConnection = false;
            Connection     = connection;
            RetryPolicy    = clientOptions.RetryOptions.ToRetryPolicy();
            InnerSender    = Connection.CreateTransportProducer(RetryPolicy);
        }
Esempio n. 3
0
        public async Task Send_Connection_Topic()
        {
            var conn    = new ServiceBusConnection(ConnString, TopicName);
            var options = new ServiceBusSenderClientOptions
            {
                RetryOptions      = new ServiceBusRetryOptions(),
                ConnectionOptions = new ServiceBusConnectionOptions()
                {
                    TransportType = ServiceBusTransportType.AmqpWebSockets,
                    Proxy         = new WebProxy("localHost")
                }
            };

            options.RetryOptions.Mode = ServiceBusRetryMode.Exponential;
            var sender = new ServiceBusSenderClient(conn, options);

            await sender.SendAsync(GetMessage());
        }
Esempio n. 4
0
        public async Task Send_Connection_Topic()
        {
            await using (var scope = await ServiceBusScope.CreateWithTopic(enablePartitioning: false, enableSession: false))
            {
                var options = new ServiceBusSenderClientOptions
                {
                    RetryOptions      = new ServiceBusRetryOptions(),
                    ConnectionOptions = new ServiceBusConnectionOptions()
                    {
                        TransportType = ServiceBusTransportType.AmqpWebSockets,
                        Proxy         = WebRequest.DefaultWebProxy
                    }
                };
                options.RetryOptions.Mode = ServiceBusRetryMode.Exponential;

                await using var sender = new TopicSenderClient(TestEnvironment.ServiceBusConnectionString, scope.TopicName, options);
                await sender.SendAsync(GetMessage());
            }
        }
Esempio n. 5
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="ServiceBusSender"/> class.
        /// </summary>
        ///
        /// <param name="fullyQualifiedNamespace">The fully qualified Service Bus namespace to connect to.  This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param>
        /// <param name="entityName">The name of the specific Service Bus entity to associated the producer with.</param>
        /// <param name="credential">The Azure managed identity credential to use for authorization.  Access controls may be specified by the Service Bus namespace or the requested Service Bus entity, depending on Azure configuration.</param>
        /// <param name="clientOptions">A set of options to apply when configuring the producer.</param>
        ///
        public ServiceBusSender(
            string fullyQualifiedNamespace,
            string entityName,
            TokenCredential credential,
            ServiceBusSenderClientOptions clientOptions = default)
        {
            Argument.AssertNotNullOrEmpty(fullyQualifiedNamespace, nameof(fullyQualifiedNamespace));
            Argument.AssertNotNullOrEmpty(fullyQualifiedNamespace, nameof(fullyQualifiedNamespace));
            Argument.AssertNotNullOrEmpty(entityName, nameof(entityName));
            Argument.AssertNotNull(credential, nameof(credential));

            clientOptions     = clientOptions?.Clone() ?? new ServiceBusSenderClientOptions();
            ClientDiagnostics = new ClientDiagnostics(clientOptions);

            OwnsConnection = true;
            Connection     = new ServiceBusConnection(fullyQualifiedNamespace, entityName, credential, clientOptions.ConnectionOptions);
            RetryPolicy    = clientOptions.RetryOptions.ToRetryPolicy();
            InnerSender    = Connection.CreateTransportProducer(RetryPolicy);
        }
Esempio n. 6
0
        public async Task Send_Topic_Session()
        {
            var conn    = new ServiceBusConnection(ConnString, "joshtopic");
            var options = new ServiceBusSenderClientOptions
            {
                RetryOptions      = new ServiceBusRetryOptions(),
                ConnectionOptions = new ServiceBusConnectionOptions()
                {
                    TransportType = ServiceBusTransportType.AmqpWebSockets,
                    Proxy         = new WebProxy("localHost")
                }
            };

            options.RetryOptions.Mode = ServiceBusRetryMode.Exponential;
            var sender  = new ServiceBusSenderClient(conn, options);
            var message = GetMessage();

            message.SessionId = "1";
            await sender.SendAsync(message);
        }
 public async Task Send_Topic_Session()
 {
     await using (var scope = await ServiceBusScope.CreateWithTopic(enablePartitioning: false, enableSession: false))
     {
         await using var conn = new ServiceBusConnection(TestEnvironment.ServiceBusConnectionString, scope.TopicName);
         var options = new ServiceBusSenderClientOptions
         {
             RetryOptions      = new ServiceBusRetryOptions(),
             ConnectionOptions = new ServiceBusConnectionOptions()
             {
                 TransportType = ServiceBusTransportType.AmqpWebSockets,
                 Proxy         = new WebProxy("localHost")
             }
         };
         options.RetryOptions.Mode = ServiceBusRetryMode.Exponential;
         await using var sender    = new ServiceBusSenderClient(conn, options);
         var message = GetMessage();
         message.SessionId = "1";
         await sender.SendAsync(message);
     }
 }
Esempio n. 8
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="ServiceBusSender"/> class.
 /// </summary>
 ///
 /// <param name="connectionString">The connection string to use for connecting to the Service Bus namespace; it is expected that the Service Bus entity name and the shared key properties are contained in this connection string.</param>
 /// <param name="clientOptions">The set of options to use for this consumer.</param>
 ///
 /// <remarks>
 ///   If the connection string is copied from the Service Bus namespace, it will likely not contain the name of the desired Service Bus entity,
 ///   which is needed.  In this case, the name can be added manually by adding ";EntityPath=[[ Service Bus entity NAME ]]" to the end of the
 ///   connection string.  For example, ";EntityPath=orders-queue".
 ///
 ///   If you have defined a shared access policy directly on the Service Bus entity itself, then copying the connection string from that
 ///   Service Bus entity will result in a connection string that contains the name.
 /// </remarks>
 ///
 public ServiceBusSender(string connectionString, ServiceBusSenderClientOptions clientOptions)
     : this(connectionString, null, clientOptions)
 {
 }