public MessageDeserializationRejectionHandler(RabbitMQConnectionPool connectionPool, string exchangeName = "",
     string rejectionRoutingKey = "RejectedMessages", ISerializer serializer = null)
 {
     _rabbitMQClient = new RabbitMQClient(connectionPool, serializer);
     _exchangeName = exchangeName;
     _rejectionRoutingKey = rejectionRoutingKey;
     _serializer = serializer ?? new JsonSerializer();
 }
 public MessageDeserializationRejectionHandler(IQueueClient rabbitMQClient, string exchangeName = "",
     string rejectionRoutingKey = "RejectedMessages", ISerializer serializer = null)
 {
     _rabbitMQClient = rabbitMQClient;
     _exchangeName = exchangeName;
     _rejectionRoutingKey = rejectionRoutingKey;
     _serializer = serializer ?? new JsonSerializer();
 }
Exemple #3
0
        public async Task Start()
        {
            await _outputService.Start();

            _queueClient = new QueueClient(_options.CurrentValue.QueueConnectionString, _options.CurrentValue.QueueName);

            await ShowLastBuildStatus();

            // Register QueueClient's MessageHandler and receive messages in a loop
            RegisterOnMessageHandlerAndReceiveMessages();
        }
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogDebug("PostingRequestDlqManagerService is starting.");

            _queueClient = new QueueClient(_settings.SyncServiceBusConnectionString,
                                           $"{_settings.PostingRequestSyncRequestQueueName}");
            _deadLetterQueueClient = new QueueClient(_settings.SyncServiceBusConnectionString,
                                                     $"{_settings.PostingRequestSyncRequestQueueName}/$DeadLetterQueue");
            RegisterOnMessageHandlerAndReceiveMessages();
            return(Task.CompletedTask);
        }
        void Intialize()
        {
            queueClient = new QueueClient(ServiceBusConnectionString, QueueName);
            topicClient = new TopicClient(ServiceBusConnectionString, TopicName);
            Console.WriteLine("======================================================");
            Console.WriteLine("Press any key to exit after receiving all the messages.");
            Console.WriteLine("======================================================");

            // Register QueueClient's MessageHandler and receive messages in a loop
            //RegisterOnMessageHandlerAndReceiveMessages();
        }
 public void Start()
 {
     try
     {
         _queueClient = new QueueClient(_config.ConnectionString, _config.QueueName);
     }
     catch (Exception e)
     {
         Console.WriteLine($"EventPublishingManager: {e.Message}");
     }
 }
Exemple #7
0
        protected void InitializeEventBlock(ServiceBusConnectionStringBuilder serviceBusConnectionStringBuilder, ReceiveMode mode, RetryPolicy retryPolicy, Action <T> action, Func <ExceptionReceivedEventArgs, Task> onError, CancellationToken cancellationToken, ILoggerFactory loggerFactory)
        {
            _reciever = CreateMessageSender(serviceBusConnectionStringBuilder, mode, retryPolicy);
            //   _messageHandlerOptions = messageHandlerOptions ?? DefaultMessageHandlerOptions;
            _cancellationToken = cancellationToken;
            _action            = action;

            _messageHandlerOptions = new MessageHandlerOptions(onError);

            _logger = loggerFactory?.CreateLogger(nameof(QueueEventBlock <T>));
        }
Exemple #8
0
        static void Main(string[] args)
        {
            MainAsync().GetAwaiter().GetResult();

            string QueueName = args[0];
            string ServiceBusConnectionString = args[1];

            queueClient = new QueueClient(ServiceBusConnectionString, QueueName);

            Console.WriteLine(DateTime.Now);
        }
Exemple #9
0
 public JobQueueHandler(
     IQueueClient pullQueueClient,
     IQueueClient pushQueueClient,
     IOrderRepository repository,
     Subject <JobActivity> activitySubject)
 {
     this.pullQueueClient = pullQueueClient ?? throw new ArgumentNullException(nameof(pullQueueClient));
     this.pushQueueClient = pushQueueClient ?? throw new ArgumentNullException(nameof(pushQueueClient));
     this.repository      = repository ?? throw new ArgumentNullException(nameof(repository));
     this.activitySubject = activitySubject ?? throw new ArgumentNullException(nameof(activitySubject));
 }
        public AzServiceBusConsumer(IConfiguration configuration, IPurchaseAppService purchaseAppService)
        {
            _configuration      = configuration;
            _purchaseAppService = purchaseAppService;

            var serviceBusConnectionString = _configuration.GetValue <string>("ServiceBusConnectionString");

            warriorPersonAddMessageReceiverClient    = new QueueClient(serviceBusConnectionString, "warriorpersonaddedmessagequeue");
            warriorPersonUpdateMessageReceiverClient = new QueueClient(serviceBusConnectionString, "warriorpersonupdatedmessagequeue");
            warriorPersonDeleteMessageReceiverClient = new QueueClient(serviceBusConnectionString, "warriorpersondeletedmessagequeue");
        }
        public FareDealStagingStartable(IOptionsSnapshot <FareDealStagingOptions> options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.options = options;

            this.queueClient = new QueueClient(this.options.Value.ServiceBusConnectionString, this.options.Value.ImportQueueName, ReceiveMode.PeekLock);
        }
        public FHIRCDSSyncAgentPostProcess2()
        {
            string _sbcfhirupdates = Utils.GetEnvironmentVariable("FP_FHIRUPDATES");

            _fhirSupportedResources = Utils.GetEnvironmentVariable("FP_FHIRMappedResources", "").Split(",");
            if (!string.IsNullOrEmpty(_sbcfhirupdates))
            {
                ServiceBusConnectionStringBuilder sbc = new ServiceBusConnectionStringBuilder(_sbcfhirupdates);
                _queueClient = new QueueClient(sbc);
            }
        }
Exemple #13
0
 private static async Task ReceiveMessagesAsync()
 {
     _queueClient = new QueueClient(QueueConnectionString, QueuePath);
     _queueClient.RegisterMessageHandler(MessageHandler,
                                         new MessageHandlerOptions(ExceptionHandler)
     {
         AutoComplete = false
     });
     Console.ReadLine();
     await _queueClient.CloseAsync();
 }
Exemple #14
0
        static async Task Main(string[] args)
        {
            queueClient = new QueueClient(ServiceBusConnectionString, QueueName);

            // Recieve Message from ServiceBus
            var messageHandlerOptions = new MessageHandlerOptions(OnException);

            queueClient.RegisterMessageHandler(OnMessage, messageHandlerOptions);

            Thread.Sleep(Timeout.Infinite);
        }
        public AzureEventBus(IOptions <Eventconfiguration> options, ILogger <AzureEventBus> logger, IServiceProvider serviceProvider)
        {
            if (options.Value == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _queueClient     = new QueueClient(options.Value.ConnectrionString, options.Value.QueueName);
            _logger          = logger;
            _serviceProvider = serviceProvider;
            RegisterOnMessageHandlerAndReceiveMessages();
        }
Exemple #16
0
        static Task ReceiveMessagesAsync()
        {
            queueClient = new QueueClient(connectionString, queueName, ReceiveMode.PeekLock);
            MessageHandlerOptions options = new MessageHandlerOptions(ExceptionHandler)
            {
                AutoComplete       = false,
                MaxConcurrentCalls = 1,
            };

            queueClient.RegisterMessageHandler(MessageHandlerAsync, options);
            return(Task.CompletedTask);
        }
Exemple #17
0
        public VideoProcessedNotifier(string queueName = DefaultQueueName)
        {
            string serviceBusConnectionString = Environment.GetEnvironmentVariable(ENV_SERVICEBUS);

            if (string.IsNullOrWhiteSpace(serviceBusConnectionString))
            {
                throw new ApplicationException($"Missing service bus connection string in env variable: {ENV_SERVICEBUS}");
            }

            _queueClient = new QueueClient(serviceBusConnectionString, queueName);
            Logger.Log($"Connected to queue {queueName}");
        }
Exemple #18
0
        private void ConnectToQueue()
        {
            _queueClient = new QueueClient(_config[ENV_SERVICEBUS], QueueName);

            // Register the function that processes messages.
            _queueClient.RegisterMessageHandler(ProcessMessagesAsync, (e) =>
            {
                _logger.LogError($"Error processing notification message: {e.Exception.Message}");
                return(Task.CompletedTask);
            });
            _logger.LogInformation($"Connected to queue {QueueName}.");
        }
        public async Task <IWrappedResponse> CancelScheduledPostingRequestsAsync(long sequenceNumber)
        {
            _queueClient = new QueueClient(_syncServiceBusConnectionString,
                                           _postingRequestSyncRequestQueueName, retryPolicy: RetryPolicy.Default);

            await _queueClient.CancelScheduledMessageAsync(sequenceNumber);

            return(new WrappedResponse
            {
                ResultType = ResultType.Ok
            });
        }
Exemple #20
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _cancellationToken = cancellationToken;
            _client            = await _clientFactory.GetQueueClient <T>().ConfigureAwait(false);

            if (!await _managementClient.QueueExistsAsync(_client.QueueName, _cancellationToken).ConfigureAwait(false))
            {
                try
                {
                    await _managementClient.CreateQueueAsync(new QueueDescription(_client.Path)
                    {
                        EnableBatchedOperations = _configuration.CreationOptions.EnableBatchedOperations,
                        EnablePartitioning      = _configuration.CreationOptions.EnablePartitioning,
                    }, _cancellationToken).ConfigureAwait(false);
                }
                catch (ServiceBusException e)
                {
                    _log.Error(e, "Failed to create queue {QueueName}", _client.QueueName);
                    throw;
                }
            }
            _deadLetterLimit      = Settings.DeadLetterDeliveryLimit;
            _client.PrefetchCount = Settings.PrefetchCount;

            _messageReceiver = new StoppableMessageReceiver(_client.ServiceBusConnection, _client.QueueName, ReceiveMode.PeekLock, null, Settings.PrefetchCount);

            var options = new StoppableMessageReceiver.MessageHandlerOptions(OnExceptionReceivedAsync)
            {
                AutoComplete         = false,
                MaxAutoRenewDuration = Settings.MessageLockTimeout,
                MaxConcurrentCalls   = Settings.MaxConcurrentCalls
            };

            _messageReceiver.RegisterStoppableMessageHandler(options, Handler);

#pragma warning disable 4014
            // ReSharper disable once MethodSupportsCancellation
            Task.Run(() =>
            {
                _cancellationToken.WaitHandle.WaitOne();
                //Cancellation requested
                try
                {
                    _log.Information($"Closing ServiceBus channel receiver for {typeof(T).Name}");
                    _messageReceiver.StopPump();
                }
                catch (Exception)
                {
                    //Swallow
                }
            });
#pragma warning restore 4014
        }
Exemple #21
0
        public static async Task Main(string[] args)
        {
            // Config do service bus
            queueClient = new QueueClient(ServiceBusConnectionString, QueueName);

            // Envia a mensagem para a fila
            await SendMessagesAsync().ConfigureAwait(true);

            // Finaliza
            Console.ReadKey();
            await queueClient.CloseAsync();
        }
Exemple #22
0
 public VerifyEmailModel(
     SignInManager <User> signInManager,
     UserManager <User> userManager,
     IEnumerable <IQueueClient> queueClients,
     IOptions <ServiceBusOptions> serviceBusOptions,
     ILogger <ExternalLoginModel> logger)
 {
     _signInManager    = signInManager;
     _userManager      = userManager;
     _emailQueueClient = queueClients.Single(x => x.QueueName == serviceBusOptions.Value.EmailQueueName);
     _logger           = logger;
 }
        public ServiceBusClient()
        {
            this.queueClient = new QueueClient(this.ServiceBusConnectionString, this.QueueName);

            var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
            {
                MaxConcurrentCalls = 1,
                AutoComplete       = false
            };

            queueClient.RegisterMessageHandler(ProcessMessagesAsync, messageHandlerOptions);
        }
Exemple #24
0
        public static Task Send <T>(T message)
        {
            if (queueClient == null)
            {
                queueClient = new QueueClient(ServiceBusConnectionString, QueueName);
            }


            var strMessage = JsonConvert.SerializeObject(message);

            return(queueClient.SendAsync(new Message(Encoding.UTF8.GetBytes(strMessage))));
        }
        private static async Task MainAsync()
        {
            // queue
            queueClient = new QueueClient(ServiceBusConnectionString, QueueName);
            queueClient.RegisterPlugin(new EnvPlugin.EnvPlugin(_environment.EnvironmentName));
            await SendMessagesAsync(10);

            // topic
            topicClient = new TopicClient(ServiceBusConnectionString, TopicName);
            topicClient.RegisterPlugin(new EnvPlugin.EnvPlugin(_environment.EnvironmentName));
            await SendTopicMessagesAsync(10);
        }
Exemple #26
0
        private static async Task MainAsync()
        {
            _queueClient = new QueueClient(ConnectionStringServiceBus, QueueName, ReceiveMode.PeekLock);

            Console.WriteLine("Press ctrl-c to stop receiving messages.");

            ReceiveMessages();

            Console.ReadKey();
            // Close the client after the ReceiveMessages method has exited.
            await _queueClient.CloseAsync();
        }
 public AzureServiceBusClient(string emiter, IDispatcherSerializer dispatcherSerializer, IQueueClient queueClient,
                              AzureServiceBusClientConfiguration configuration)
 {
     if (string.IsNullOrWhiteSpace(emiter))
     {
         throw new ArgumentNullException(nameof(emiter));
     }
     _dispatcherSerializer = dispatcherSerializer ?? throw new ArgumentNullException(nameof(dispatcherSerializer));
     _emiter        = emiter;
     _configuration = configuration;
     _queueClient   = queueClient;
 }
Exemple #28
0
 public AdvancedAsyncProcessingWorker(IQueueClient queueClient, string queueName,
                                      Func <T, RabbitMQConsumerContext, CancellationToken, Task> callbackFunc, TimeSpan processingTimeout,
                                      ExceptionHandlingStrategy exceptionHandlingStrategy = ExceptionHandlingStrategy.Requeue,
                                      int invokeRetryCount = 1, int invokeRetryWaitMilliseconds = 0,
                                      IConsumerCountManager consumerCountManager = null, IMessageRejectionHandler messageRejectionHandler = null,
                                      ILogger logger = null, ushort prefetchCount = 1)
     : base(queueClient, queueName, exceptionHandlingStrategy, invokeRetryCount, invokeRetryWaitMilliseconds,
            consumerCountManager, messageRejectionHandler, logger, prefetchCount)
 {
     _callbackFunc      = callbackFunc;
     _processingTimeout = processingTimeout;
 }
Exemple #29
0
        static async Task MainAsync()
        {
            QueueClient = new QueueClient(ServiceBusConnectionString, QueueName);

            Console.WriteLine("================================================");
            Console.WriteLine("Sending messages");
            Console.WriteLine("================================================");

            await SendMessagesAsync(numberOfMessages);

            await QueueClient.CloseAsync();
        }
        public async Task ReceiveMessage()
        {
            queueClient = new QueueClient(ServiceBusConnectionString, QueueName);

            MessageHandlerOptions messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
            {
                AutoComplete       = false,
                MaxConcurrentCalls = 1
            };

            queueClient.RegisterMessageHandler(ProcessMessagesAsync, messageHandlerOptions);
        }
Exemple #31
0
        private static async Task MainAsync(string[] args)
        {
            queueClient = new QueueClient(ServiceBusConnectionString, QueueName, ReceiveMode.PeekLock);

            await SendMessagesToQueue(10);

            // Close the client after the ReceiveMessages method has exited.
            await queueClient.CloseAsync();

            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }
Exemple #32
0
 public async Task SendMessage(string queue, Message msg)
 {
     try
     {
         SbQueueClient = new QueueClient(config.GetVal("ServiceBus:Endpoint"), config.GetVal("Queues:" + queue));
         await SbQueueClient.SendAsync(msg);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
 public QueueStructureInitializer(IQueueClient queueClient, string exchangeName)
 {
     _queueClient = queueClient;
     _exchangeName = exchangeName;
 }
Exemple #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureCommandQueue"/> class.
 /// </summary>
 public AzureCommandQueue(IQueueClient client)
 {
     this.client = client;
 }
Exemple #35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureCommandQueue"/> class.
 /// </summary>
 public AzureCommandQueue(string connectionString)
 {
     this.client = new DefaultQueueClient(QueueClient.CreateFromConnectionString(connectionString, QueueName));
 }
 public BandOperator(IQueueClient<FanSwitchCommand> fanStatusPoster)
 {
   _fanStatusPoster = fanStatusPoster;
 }