예제 #1
0
        private async Task ExceptionReceivedHandler(ExceptionReceivedEventArgs exceptionReceivedEventArgs)
        {
            if (exceptionReceivedEventArgs.Exception is MessagingEntityNotFoundException)
            {
                // reinitalize all
                try
                {
                    await manager.CreateIfNotExisted().ConfigureAwait(false);

                    if (isTopic)
                    {
                        await manager.AddSubscribtionIfNotExisted(subscriptionId).ConfigureAwait(false);
                    }
                }
                catch (Exception ex)
                {
                    logger.LogError($"ServiceBus: failed to create client: {setting.ConnectionString}: {ex}");
                }
            }

            logger.LogError(exceptionReceivedEventArgs.Exception, "Message handler encountered an exception");
            var context = exceptionReceivedEventArgs.ExceptionReceivedContext;

            logger.LogDebug("Endpoint: {Endpoint}, Entity Path: {EntityPath}, Executing Action: {Action}", context.Endpoint, context.EntityPath, context.Action);
        }
예제 #2
0
        public ServiceBusSender(ServiceBusSetting setting, ILoggerFactory logger)
        {
            this.logger  = logger.CreateLogger <ServiceBusSender <T> >();
            this.setting = setting;
            manager      = new ServiceBusManager(setting, logger);
            manager.CreateIfNotExisted().Wait();

            sender = new MessageSender(setting.ConnectionString, setting.IsTopic ? setting.TopicPath : setting.QueueName);
        }
예제 #3
0
        public ServiceBusReceiver(ServiceBusSetting setting, IMessageProcessor <T> processor, ILoggerFactory logger)
        {
            this.logger    = logger.CreateLogger <ServiceBusReceiver <T> >();
            this.processor = processor;
            this.setting   = setting;

            isTopic = setting.IsTopic;
            manager = new ServiceBusManager(setting, logger);
            manager.CreateIfNotExisted().Wait();

            if (isTopic)
            {
                manager.AddSubscribtionIfNotExisted(subscriptionId).Wait();
            }

            receiver = new MessageReceiver(setting.ConnectionString, isTopic ? $"{setting.TopicPath}/subscriptions/{subscriptionId}" : setting.QueueName);
        }
예제 #4
0
        public async Task SendMessagesAsync(T payload)
        {
            string data    = JsonSerializer.Serialize <T>(payload);
            var    message = new Message(Encoding.UTF8.GetBytes(data));

            try
            {
                await sender.SendAsync(message).ConfigureAwait(false);
            }
            catch (MessagingEntityNotFoundException)
            {
                try
                {
                    await manager.CreateIfNotExisted().ConfigureAwait(false);

                    await sender.SendAsync(message).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    logger.LogError($"ServiceBus: failed to create client: {setting.ConnectionString}: {ex}");
                }
            }
        }