Пример #1
0
        public void Reject(Message message, bool requeue)
        {
            _messageReceiver.Abandon(message.Header.Bag[LockToken].ToString());

            if (requeue)
            {
                Requeue(message, 0);
            }
        }
Пример #2
0
 public void Requeue(Message message, int delayMilliseconds)
 {
     if (delayMilliseconds > 0)
     {
         _messageProducer.SendWithDelay(message, delayMilliseconds);
     }
     else
     {
         _messageProducer.Send(message);
     }
 }
Пример #3
0
        public void When_requeue_is_called_and_the_delay_is_more_than_zero_the_sendWithDelay_method_is_called()
        {
            var messageLockTokenOne = Guid.NewGuid();
            var messageHeader       = new MessageHeader(Guid.NewGuid(), "topic", MessageType.MT_EVENT);
            var message             = new Message(messageHeader, new MessageBody("body"));

            message.Header.Bag.Add("LockToken", messageLockTokenOne);

            _azureServiceBusConsumer.Requeue(message, 100);

            _mockMessageProducer.Verify(x => x.SendWithDelay(message, 100), Times.Once);
        }
Пример #4
0
        /// <summary>
        /// Maps to message.
        /// </summary>
        /// <param name="command">The command to serialize.</param>
        /// <returns>Paramore.Brighter.Message.</returns>
        /// <exception cref="System.ArgumentNullException">request</exception>
        public Paramore.Brighter.Message MapToMessage(BrighterCommand command)
        {
            _ = command ?? throw new ArgumentNullException(nameof(command));
            var header = new MessageHeader(
                messageId: ((Paramore.Brighter.IRequest)command).Id,
                topic: command.Command.AggregateType,
                messageType: MessageType.MT_COMMAND,
                correlationId: command.Command.CorrelationId.ToGuidOrDefault());
            var body    = new MessageBody(JsonConvert.SerializeObject(new Envelope(command.Command)));
            var message = new Paramore.Brighter.Message(header, body);

            return(message);
        }
Пример #5
0
        /// <summary>
        /// Maps a command to a brighter message.
        /// </summary>
        /// <param name="domainEvent">The domain event.</param>
        /// <returns>Paramore.Brighter.Message.</returns>
        /// <exception cref="System.ArgumentNullException">domainEvent</exception>
        public Paramore.Brighter.Message MapToMessage(BrighterEvent domainEvent)
        {
            _ = domainEvent ?? throw new ArgumentNullException(nameof(domainEvent));
            var header = new MessageHeader(
                messageId: domainEvent.Id,
                topic: domainEvent.Event.AggregateType,
                messageType: MessageType.MT_EVENT,
                correlationId: domainEvent.Event.CorrelationId.ToGuidOrDefault());
            var body    = new MessageBody(JsonConvert.SerializeObject(new Envelope(domainEvent.Event)));
            var message = new Paramore.Brighter.Message(header, body);

            return(message);
        }
Пример #6
0
        public void When_reject_is_called_the_abandon_method_is_called_with_the_correct_lock_token()
        {
            var messageLockTokenOne = Guid.NewGuid().ToString();

            var messageHeader = new MessageHeader(Guid.NewGuid(), "topic", MessageType.MT_EVENT);

            var message = new Message(messageHeader, new MessageBody("body"));

            message.Header.Bag.Add("LockToken", messageLockTokenOne);

            _azureServiceBusConsumer.Reject(message, false);

            _messageReceiver.Verify(x => x.Abandon(messageLockTokenOne), Times.Once);
        }
Пример #7
0
        public Message[] Receive(int timeoutInMilliseconds)
        {
            EnsureSubscription();

            var messages         = _messageReceiver.Receive(_batchSize, TimeSpan.FromMilliseconds(timeoutInMilliseconds)).Result;
            var messagesToReturn = new List <Message>();

            foreach (var azureServiceBusMessage in messages)
            {
                var messageBody = System.Text.Encoding.Default.GetString(azureServiceBusMessage.MessageBodyValue);

                var message = new Message(new MessageHeader(Guid.NewGuid(), _topicName, MessageType.MT_EVENT), new MessageBody(messageBody));

                message.Header.Bag.Add(LockToken, azureServiceBusMessage.LockToken);
                messagesToReturn.Add(message);
            }

            return(messagesToReturn.ToArray());
        }
Пример #8
0
 /// <summary>
 /// Maps to request.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <returns>T.</returns>
 public BrighterCommand MapToRequest(Paramore.Brighter.Message message)
 {
     _ = message ?? throw new ArgumentNullException(nameof(message));
     return(new BrighterCommand((ICommand)JsonConvert.DeserializeObject <Envelope>(message.Body.Value).Message));
 }
Пример #9
0
 public void Acknowledge(Message message)
 {
     _messageReceiver.Complete(message.Header.Bag[LockToken].ToString());
 }