public Task StartAsync(OnMessage messageHandler, OnMessageException exceptionHandler, OnMessageOptions options)
        {
            lock (_initializationLock)
            {
                if (_initialized)
                    throw new MessageReceiverException("Message receiver has already been initialized.");

                if (messageHandler == null)
                    throw new ArgumentNullException("messageHandler");

                if (options == null)
                    options = _defaultOptions;

                // Log.
                ServiceBusEventSource.Log.MessagePumpStart(GetType().Name, Namespace, Path, options.AutoRenewTimeout, options.MaxConcurrentCalls);

                // Initialize the handler options.
                var messageOptions = new Microsoft.ServiceBus.Messaging.OnMessageOptions();
                messageOptions.AutoComplete = options.AutoComplete;
                messageOptions.AutoRenewTimeout = options.AutoRenewTimeout;
                messageOptions.MaxConcurrentCalls = options.MaxConcurrentCalls;
                messageOptions.ExceptionReceived += (s, e) => 
                {
                    if (e.Exception != null)
                    {
                        // Log.
                        ServiceBusEventSource.Log.MessagePumpExceptionReceived(Namespace, Path,
                            e.Action, e.Exception);

                        // Handle exception.
                        if (exceptionHandler != null)
                            exceptionHandler(e.Action, e.Exception);
                    }
                };

                // Mark receiver as initialized.
                _initialized = true;

                // Start.
                return OnStartAsync(messageHandler, messageOptions);
            }
        }
 public SubscriptionMessagePump(SubscriptionClient client, OnMessageOptions options = null)
     : base(client, client.Mode, client.MessagingFactory.GetShortNamespaceName(), client.TopicPath + "/" + client.Name, options)
 {
     _client = client;
 }
 public static Task StartAsync(this IMessagePump pump, OnMessage messageHandler, OnMessageOptions options)
 {
     return pump.StartAsync(messageHandler, null, options);
 }
 public static Task StartAsync(this IMessagePump pump, OnMessage messageHandler, OnMessageOptions options)
 {
     return(pump.StartAsync(messageHandler, null, options));
 }
 protected EventDrivenMessagePump(MessageClientEntity messageClient, ReceiveMode mode, string @namespace, string path, OnMessageOptions defaultOptions)
     : base(mode, @namespace, path)
 {
     _messageClient = messageClient;
     _defaultOptions = defaultOptions ?? new OnMessageOptions();
 }
Exemple #6
0
 public QueueMessagePump(QueueClient client, OnMessageOptions options = null)
     : base(client, client.Mode, client.MessagingFactory.GetShortNamespaceName(), client.Path, options)
 {
     _client = client;
 }
Exemple #7
0
        public Task StartAsync(OnMessage messageHandler, OnMessageException exceptionHandler, OnMessageOptions options)
        {
            lock (_initializationLock)
            {
                if (_initialized)
                {
                    throw new MessageReceiverException("Message receiver has already been initialized.");
                }

                if (messageHandler == null)
                {
                    throw new ArgumentNullException("messageHandler");
                }

                if (options == null)
                {
                    options = _defaultOptions;
                }

                // Log.
                ServiceBusEventSource.Log.MessagePumpStart(GetType().Name, Namespace, Path, options.AutoRenewTimeout, options.MaxConcurrentCalls);

                // Initialize the handler options.
                var messageOptions = new Microsoft.ServiceBus.Messaging.OnMessageOptions();
                messageOptions.AutoComplete       = options.AutoComplete;
                messageOptions.AutoRenewTimeout   = options.AutoRenewTimeout;
                messageOptions.MaxConcurrentCalls = options.MaxConcurrentCalls;
                messageOptions.ExceptionReceived += (s, e) =>
                {
                    if (e.Exception != null)
                    {
                        // Log.
                        ServiceBusEventSource.Log.MessagePumpExceptionReceived(Namespace, Path,
                                                                               e.Action, e.Exception);

                        // Handle exception.
                        if (exceptionHandler != null)
                        {
                            exceptionHandler(e.Action, e.Exception);
                        }
                    }
                };

                // Mark receiver as initialized.
                _initialized = true;

                // Start.
                return(OnStartAsync(messageHandler, messageOptions));
            }
        }
Exemple #8
0
 protected EventDrivenMessagePump(MessageClientEntity messageClient, ReceiveMode mode, string @namespace, string path, OnMessageOptions defaultOptions)
     : base(mode, @namespace, path)
 {
     _messageClient  = messageClient;
     _defaultOptions = defaultOptions ?? new OnMessageOptions();
 }
Exemple #9
0
 public QueueMessagePump(QueueClient client, OnMessageOptions options = null)
     : base(client, client.Mode, client.MessagingFactory.GetShortNamespaceName(), client.Path, options)
 {
     _client = client;
 }
 public SubscriptionMessagePump(SubscriptionClient client, OnMessageOptions options = null)
     : base(client, client.Mode, client.MessagingFactory.GetShortNamespaceName(), client.TopicPath + "/" + client.Name, options)
 {
     _client = client;
 }