Esempio n. 1
0
        public string Test()
        {
            mqManager.Receive <string>(x =>
            {
                System.Console.WriteLine(x);
            });

            return("Test");
        }
        private Message ReceiveMessage(System.Messaging.MessageQueue queue)
        {
            var messageQueueTransaction = new System.Messaging.MessageQueueTransaction();

            messageQueueTransaction.Begin();

            var message = _messageQueueManager.Receive(queue, TimeSpan.FromMilliseconds(10), messageQueueTransaction);

            messageQueueTransaction.Commit();

            return(message);
        }
Esempio n. 3
0
        private ITransactionalMessage ReceiveMessage()
        {
            var messageQueueTransaction = CreateTransaction();

            messageQueueTransaction?.Begin();

            try
            {
                using (var memoryStream = new MemoryStream())
                {
                    var message = MessageQueueManager.Receive(MessageQueue, TimeSpan.Zero, messageQueueTransaction?.Transaction);

                    if (message == null)
                    {
                        Logger.Debug($"Receive timeout from {Name}");
                    }
                    else
                    {
                        Logger.Debug("Received message chunk ({Chunk}/{NumberOfChunks}) from {QueueName}", 1, message.AppSpecific, Name);
                    }

                    var messageNumber = 0;

                    while (message != null && ++messageNumber <= message.AppSpecific)
                    {
                        message.BodyStream.CopyTo(memoryStream);

                        if (messageNumber < message.AppSpecific)
                        {
                            message = MessageQueueManager.ReceiveByCorrelationId(MessageQueue, message.Id, TimeSpan.Zero, messageQueueTransaction?.Transaction);

                            if (message == null)
                            {
                                throw new MissingChunkException(Name, messageNumber);
                            }
                        }
                    }

                    return(CreateTransactionalMessage(memoryStream, messageQueueTransaction));
                }
            }
            catch (Exception)
            {
                messageQueueTransaction?.Abort();
                messageQueueTransaction?.Dispose();

                throw;
            }
        }
        private void AddMessageToQueue(System.Messaging.MessageQueue messageQueue, object dto)
        {
            var body = new QueueMessage {
                MessageBody = dto.SerializeToJson(new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All
                }), MessageType = dto.GetType()
            };

            var message = new Message
            {
                Body        = body,
                AppSpecific = 1,
                BodyStream  = new MemoryStream(Encoding.UTF8.GetBytes(body.SerializeToJson(new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All
                })))
            };

            _messageQueueManager.Receive(messageQueue, Arg.Any <TimeSpan>(), Arg.Any <System.Messaging.MessageQueueTransaction>()).Returns(message);
            _messageQueueManager.EndPeek(messageQueue, Arg.Any <IAsyncResult>()).Returns(message);
            _messageQueueManager.BeginPeek(messageQueue, Arg.Any <TimeSpan>()).Returns((IAsyncResult)null);
        }
Esempio n. 5
0
 private void AddMessageToQueue(object dto)
 {
     _messageQueueManager.Receive(Arg.Any <System.Messaging.MessageQueue>(), Arg.Any <TimeSpan>(), Arg.Any <System.Messaging.MessageQueueTransaction>()).Returns(GetMessage(dto));
     _messageQueueManager.BeginPeek(Arg.Any <System.Messaging.MessageQueue>(), Arg.Any <TimeSpan>()).Returns((IAsyncResult)null);
     _messageQueueManager.EndPeek(Arg.Any <System.Messaging.MessageQueue>(), Arg.Any <IAsyncResult>()).Returns(GetMessage(dto));
 }