Exemple #1
0
        private string GetMessageInContext(Message message)
        {
            var serializedMessage = _serialisationRegister.GeTypeSerialiser(message.GetType()).Serialiser.Serialise(message);
            var context           = new { Subject = message.GetType().Name, Message = serializedMessage };

            return(JsonConvert.SerializeObject(context));
        }
        protected override void Given()
        {
            var serialiser = Substitute.For <IMessageSerialiser>();

            serialiser.Serialise(Arg.Any <Message>()).Returns(Message);
            _serialisationRegister.GeTypeSerialiser(typeof(GenericMessage)).Returns(new TypeSerialiser(typeof(GenericMessage), serialiser));
            _sns.FindTopic(TopicName).Returns(new Topic {
                TopicArn = TopicArn
            });
        }
        public void Publish(Message message)
        {
            var messageToSend = _serialisationRegister.GeTypeSerialiser(message.GetType()).Serialiser.Serialise(message);
            var messageType   = message.GetType().Name;

            Client.Publish(new PublishRequest
            {
                Subject  = messageType,
                Message  = messageToSend,
                TopicArn = Arn
            });

            EventLog.Info("Published message: '{0}' with content {1}", messageType, messageToSend);
        }
Exemple #4
0
        protected override void Given()
        {
            var messageSerializer = Substitute.For <IMessageSerialiser>();

            messageSerializer.Serialise(_message).Returns(SerialisedMessageBody);

            _sqs.ListQueues(Arg.Any <ListQueuesRequest>()).Returns(new ListQueuesResponse {
                QueueUrls = new List <string> {
                    Url
                }
            });
            _sqs.GetQueueAttributes(Arg.Any <GetQueueAttributesRequest>()).Returns(new GetQueueAttributesResponse());
            _serialisationRegister.GeTypeSerialiser(typeof(GenericMessage)).Returns(new TypeSerialiser(typeof(GenericMessage), messageSerializer));
        }
Exemple #5
0
        protected override void Given()
        {
            Sqs                   = Substitute.For <IAmazonSQS>();
            Serialiser            = Substitute.For <IMessageSerialiser>();
            SerialisationRegister = Substitute.For <IMessageSerialisationRegister>();
            Monitor               = Substitute.For <IMessageMonitor>();
            Handler               = Substitute.For <IHandler <GenericMessage> >();
            var response = GenerateResponseMessage(_messageTypeString, Guid.NewGuid());

            Sqs.ReceiveMessage(Arg.Any <ReceiveMessageRequest>()).Returns(x => response, x => new ReceiveMessageResponse());

            SerialisationRegister.GeTypeSerialiser(_messageTypeString).Returns(new TypeSerialiser(typeof(GenericMessage), Serialiser));
            DeserialisedMessage = new GenericMessage {
                RaisingComponent = "Component"
            };
            Serialiser.Deserialise(Arg.Any <string>(), typeof(GenericMessage)).Returns(x => DeserialisedMessage);
        }
Exemple #6
0
        public void ProcessMessageAction(Amazon.SQS.Model.Message message)
        {
            Message typedMessage = null;
            string  rawMessage   = null;

            try
            {
                var    body        = JObject.Parse(message.Body);
                string messageType = body["Subject"].ToString();

                rawMessage = body["Message"].ToString();
                var typeSerialiser = _serialisationRegister.GeTypeSerialiser(messageType);
                typedMessage = typeSerialiser.Serialiser.Deserialise(rawMessage, typeSerialiser.Type);

                var handlingSucceeded = true;

                if (typedMessage != null)
                {
                    List <Func <Message, bool> > handlers;
                    if (!_handlers.TryGetValue(typedMessage.GetType(), out handlers))
                    {
                        return;
                    }

                    foreach (var handle in handlers)
                    {
                        var watch = new System.Diagnostics.Stopwatch();
                        watch.Start();

                        handlingSucceeded = handle(typedMessage);

                        watch.Stop();
                        Log.Trace("Handled message - MessageType: " + messageType);
                        _messagingMonitor.HandleTime(watch.ElapsedMilliseconds);
                    }
                }

                if (handlingSucceeded)
                {
                    _queue.Client.DeleteMessage(new DeleteMessageRequest {
                        QueueUrl = _queue.Url, ReceiptHandle = message.ReceiptHandle
                    });
                }
            }
            catch (KeyNotFoundException ex)
            {
                Log.Trace("Didn't handle message {0}. No serialiser setup", rawMessage ?? "");
                _queue.Client.DeleteMessage(new DeleteMessageRequest
                {
                    QueueUrl      = _queue.Url,
                    ReceiptHandle = message.ReceiptHandle
                });
                _onError(ex, message);
            }
            catch (Exception ex)
            {
                Log.Error(ex, string.Format("Issue handling message... {0}. StackTrace: {1}", message, ex.StackTrace));
                if (typedMessage != null)
                {
                    _messagingMonitor.HandleException(typedMessage.GetType().Name);
                }
                _onError(ex, message);
            }
        }
 protected override void Given()
 {
     _serialisationRegister.GeTypeSerialiser(Arg.Any <string>()).Returns(x => { throw new Exception(); });
     _sqs.ReceiveMessage(Arg.Any <ReceiveMessageRequest>()).Returns(x => GenerateEmptyMessage());
     _sqs.When(x => x.ReceiveMessage(Arg.Any <ReceiveMessageRequest>())).Do(x => _callCount++);
 }