Пример #1
0
        static void GroupConsuemrTest()
        {
            var cancellationTokenSource = new CancellationTokenSource();
            var consumerTasks           = new List <Task>();

            for (int i = 0; i < 3; i++)
            {
                consumerTasks.Add(CreateConsumerTask(i.ToString(), cancellationTokenSource));
            }


            var producer = new EQueueProducer(brokerAddress);

            producer.Start();
            while (true)
            {
                var message = Console.ReadLine();
                if (message.Equals("q"))
                {
                    cancellationTokenSource.Cancel();
                    Task.WaitAll(consumerTasks.ToArray());
                    break;
                }
                message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff");
                var queueMessage = new EQueue.Protocols.Message(topic, 1, Encoding.UTF8.GetBytes(message));
                producer.Send(queueMessage, message);
                Console.WriteLine($"send message: {message}");
            }
        }
Пример #2
0
        public Task PublishAsync(DomainEventStreamMessage eventStream)
        {
            Ensure.NotNull(eventStream.AggregateRootId, "aggregateRootId");
            var eventMessage  = CreateEventMessage(eventStream);
            var topic         = _eventTopicProvider.GetTopic(eventStream.Events.First());
            var data          = _jsonSerializer.Serialize(eventMessage);
            var equeueMessage = new EQueueMessage(topic, (int)EQueueMessageTypeCode.DomainEventStreamMessage, Encoding.UTF8.GetBytes(data));

            return(_sendMessageService.SendMessageAsync(Producer, "events", string.Join(",", eventStream.Events.Select(x => x.GetType().Name)), equeueMessage, data, eventStream.AggregateRootId, eventStream.Id, eventStream.Items));
        }
Пример #3
0
 public void SendMessage(Producer producer, EQueueMessage message, object routingKey)
 {
     _ioHelper.TryIOAction(() =>
     {
         var result = producer.Send(message, routingKey);
         if (result.SendStatus != SendStatus.Success)
         {
             throw new IOException(result.ErrorMessage);
         }
     }, "SendQueueMessage");
 }
Пример #4
0
 public void SendMessage(Producer producer, EQueueMessage message, object routingKey)
 {
     _ioHelper.TryIOAction(() =>
     {
         var result = producer.Send(message, routingKey);
         if (result.SendStatus != SendStatus.Success)
         {
             throw new IOException(result.ErrorMessage);
         }
     }, "SendQueueMessage");
 }
Пример #5
0
        public Task PublishAsync(IApplicationMessage message)
        {
            var topic         = _messageTopicProvider.GetTopic(message);
            var data          = _jsonSerializer.Serialize(message);
            var equeueMessage = new EQueueMessage(
                topic,
                (int)EQueueMessageTypeCode.ApplicationMessage,
                Encoding.UTF8.GetBytes(data),
                _typeNameProvider.GetTypeName(message.GetType()));

            return(_sendMessageService.SendMessageAsync(Producer, "applicationMessage", message.GetType().Name, equeueMessage, data, message.Id, message.Id, message.Items));
        }
Пример #6
0
 public async Task<AsyncTaskResult> SendMessageAsync(Producer producer, EQueueMessage message, object routingKey)
 {
     try
     {
         var result = await producer.SendAsync(message, routingKey);
         if (result.SendStatus != SendStatus.Success)
         {
             return new AsyncTaskResult(AsyncTaskStatus.IOException, result.ErrorMessage);
         }
         return AsyncTaskResult.Success;
     }
     catch (Exception ex)
     {
         return new AsyncTaskResult(AsyncTaskStatus.IOException, ex.Message);
     }
 }
Пример #7
0
        public async Task <AsyncTaskResult> SendMessageAsync(Producer producer, EQueueMessage message, object routingKey)
        {
            try
            {
                var result = await producer.SendAsync(message, routingKey);

                if (result.SendStatus != SendStatus.Success)
                {
                    return(new AsyncTaskResult(AsyncTaskStatus.IOException, result.ErrorMessage));
                }
                return(AsyncTaskResult.Success);
            }
            catch (Exception ex)
            {
                return(new AsyncTaskResult(AsyncTaskStatus.IOException, ex.Message));
            }
        }
Пример #8
0
 public async Task<AsyncTaskResult> SendMessageAsync(Producer producer, EQueueMessage message, string routingKey)
 {
     try
     {
         var result = await producer.SendAsync(message, routingKey);
         if (result.SendStatus != SendStatus.Success)
         {
             _logger.ErrorFormat("EQueue message async send failed, sendResult: {0}, routingKey: {1}", result, routingKey);
             return new AsyncTaskResult(AsyncTaskStatus.IOException, result.ErrorMessage);
         }
         _logger.InfoFormat("EQueue message async send success, sendResult: {0}, routingKey: {1}", result, routingKey);
         return AsyncTaskResult.Success;
     }
     catch (Exception ex)
     {
         _logger.Error(string.Format("EQueue message async send has exception, message: {0}, routingKey: {1}", message, routingKey), ex);
         return new AsyncTaskResult(AsyncTaskStatus.IOException, ex.Message);
     }
 }
Пример #9
0
        public async Task <AsyncTaskResult> SendMessageAsync(Producer producer, EQueueMessage message, string routingKey, string messageId, string version)
        {
            try
            {
                var result = await producer.SendAsync(message, routingKey);

                if (result.SendStatus != SendStatus.Success)
                {
                    _logger.ErrorFormat("ENode message async send failed, sendResult: {0}, routingKey: {1}, messageId: {2}, version: {3}", result, routingKey, messageId, version);
                    return(new AsyncTaskResult(AsyncTaskStatus.IOException, result.ErrorMessage));
                }
                _logger.DebugFormat("ENode message async send success, sendResult: {0}, routingKey: {1}, messageId: {2}, version: {3}", result, routingKey, messageId, version);
                return(AsyncTaskResult.Success);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("ENode message async send has exception, message: {0}, routingKey: {1}, messageId: {2}, version: {3}", message, routingKey, messageId, version), ex);
                return(new AsyncTaskResult(AsyncTaskStatus.IOException, ex.Message));
            }
        }
Пример #10
0
        public Task PublishAsync(IDomainException exception)
        {
            var topic            = _exceptionTopicProvider.GetTopic(exception);
            var serializableInfo = new Dictionary <string, string>();

            exception.SerializeTo(serializableInfo);
            var data = _jsonSerializer.Serialize(new DomainExceptionMessage
            {
                UniqueId         = exception.Id,
                Timestamp        = exception.Timestamp,
                Items            = exception.Items,
                SerializableInfo = serializableInfo
            });
            var equeueMessage = new EQueueMessage(
                topic,
                (int)EQueueMessageTypeCode.ExceptionMessage,
                Encoding.UTF8.GetBytes(data),
                _typeNameProvider.GetTypeName(exception.GetType()));

            return(_sendMessageService.SendMessageAsync(Producer, "exception", exception.GetType().Name, equeueMessage, data, exception.Id, exception.Id, exception.Items));
        }
Пример #11
0
 public void SendMessage(Producer producer, EQueueMessage message, string routingKey, string messageId, string version)
 {
     try
     {
         _ioHelper.TryIOAction(() =>
         {
             var result = producer.Send(message, routingKey);
             if (result.SendStatus != SendStatus.Success)
             {
                 _logger.ErrorFormat("ENode message sync send failed, sendResult: {0}, routingKey: {1}, messageId: {2}, version: {3}", result, routingKey, messageId, version);
                 throw new IOException(result.ErrorMessage);
             }
             _logger.InfoFormat("ENode message sync send success, sendResult: {0}, routingKey: {1}, messageId: {2}, version: {3}", result, routingKey, messageId, version);
         }, "SendENodeMessage");
     }
     catch (Exception ex)
     {
         _logger.Error(string.Format("ENode message synch send has exception, message: {0}, routingKey: {1}, messageId: {2}, version: {3}", message, routingKey, messageId, version), ex);
         throw;
     }
 }
Пример #12
0
 public void SendMessage(Producer producer, EQueueMessage message, string routingKey)
 {
     try
     {
         _ioHelper.TryIOAction(() =>
         {
             var result = producer.Send(message, routingKey);
             if (result.SendStatus != SendStatus.Success)
             {
                 _logger.ErrorFormat("EQueue message sync send failed, sendResult: {0}, routingKey: {1}", result, routingKey);
                 throw new IOException(result.ErrorMessage);
             }
             _logger.InfoFormat("EQueue message sync send success, sendResult: {0}, routingKey: {1}", result, routingKey);
         }, "SendQueueMessage");
     }
     catch (Exception ex)
     {
         _logger.Error(string.Format("EQueue message synch send has exception, message: {0}, routingKey: {1}", message, routingKey), ex);
         throw;
     }
 }
Пример #13
0
 public void SendMessage(Producer producer, EQueueMessage message, string routingKey)
 {
     try
     {
         _ioHelper.TryIOAction(() =>
         {
             var result = producer.Send(message, routingKey);
             if (result.SendStatus != SendStatus.Success)
             {
                 _logger.ErrorFormat("EQueue message synch send failed, sendResult: {0}, routingKey: {1}", result, routingKey);
                 throw new IOException(result.ErrorMessage);
             }
             if (_logger.IsDebugEnabled)
             {
                 _logger.DebugFormat("EQueue message synch send success, sendResult: {0}, routingKey: {1}", result, routingKey);
             }
         }, "SendQueueMessage");
     }
     catch (Exception ex)
     {
         _logger.Error(string.Format("EQueue message synch send has exception, message: {0}, routingKey: {1}", message, routingKey), ex);
         throw;
     }
 }
Пример #14
0
        public async Task SendMessageAsync(Producer producer, string messageType, string messageClass, EQueueMessage message, string routingKey, string messageId, IDictionary <string, string> messageExtensionItems)
        {
            try
            {
                var result = await producer.SendAsync(message, routingKey).ConfigureAwait(false);

                if (result.SendStatus == SendStatus.Success)
                {
                    if (_logger.IsDebugEnabled)
                    {
                        _logger.DebugFormat("ENode {0} message send success, equeueMessageId: {1}, routingKey: {2}, messageType: {3}, messageId: {4}, messageExtensionItems: {5}",
                                            messageType,
                                            result.MessageStoreResult.MessageId,
                                            routingKey,
                                            messageClass,
                                            messageId,
                                            _jsonSerializer.Serialize(messageExtensionItems)
                                            );
                    }
                }
                else
                {
                    _logger.ErrorFormat("ENode {0} message send failed, message: {1}, sendResult: {2}, routingKey: {3}, messageType: {4}, messageId: {5}, messageExtensionItems: {6}",
                                        messageType,
                                        message,
                                        result,
                                        routingKey,
                                        messageClass,
                                        messageId,
                                        _jsonSerializer.Serialize(messageExtensionItems)
                                        );
                    throw new IOException(result.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("ENode {0} message send has exception, message: {1}, routingKey: {2}, messageType: {3}, messageId: {4}, messageExtensionItems: {5}",
                                            messageType,
                                            message,
                                            routingKey,
                                            messageClass,
                                            messageId,
                                            _jsonSerializer.Serialize(messageExtensionItems)
                                            ), ex);
                throw new IOException("Send equeue message has exception.", ex);
            }
        }
Пример #15
0
        public async Task <AsyncTaskResult> SendMessageAsync(Producer producer, string messageType, string messageClass, EQueueMessage message, string routingKey, string messageId, IDictionary <string, string> messageExtensionItems)
        {
            try
            {
                var result = await producer.SendAsync(message, routingKey);

                if (result.SendStatus != SendStatus.Success)
                {
                    _logger.ErrorFormat("ENode {0} message send failed, message: {1}, sendResult: {2}, routingKey: {3}, messageType: {4}, messageId: {5}, messageExtensionItems: {6}",
                                        messageType,
                                        message,
                                        result,
                                        routingKey,
                                        messageClass,
                                        messageId,
                                        _jsonSerializer.Serialize(messageExtensionItems)
                                        );
                    return(new AsyncTaskResult(AsyncTaskStatus.IOException, result.ErrorMessage));
                }
                _logger.InfoFormat("ENode {0} message send success, equeueMessageId: {1}, routingKey: {2}, messageType: {3}, messageId: {4}, messageExtensionItems: {5}",
                                   messageType,
                                   result.MessageStoreResult.MessageId,
                                   routingKey,
                                   messageClass,
                                   messageId,
                                   _jsonSerializer.Serialize(messageExtensionItems)
                                   );
                return(AsyncTaskResult.Success);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("ENode {0} message send has exception, message: {1}, routingKey: {2}, messageType: {3}, messageId: {4}, messageExtensionItems: {5}",
                                            messageType,
                                            message,
                                            routingKey,
                                            messageClass,
                                            messageId,
                                            _jsonSerializer.Serialize(messageExtensionItems)
                                            ), ex);
                return(new AsyncTaskResult(AsyncTaskStatus.IOException, ex.Message));
            }
        }