-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from DevJonny/issue-105
Fix #105 - Support for Binding a channel to multiple topics
- Loading branch information
Showing
4 changed files
with
150 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...Paramore.Brighter.Tests/MessagingGateway/rmq/When_binding_a_channel_to_multiple_topics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Paramore.Brighter.MessagingGateway.RMQ; | ||
using Paramore.Brighter.MessagingGateway.RMQ.MessagingGatewayConfiguration; | ||
using Xunit; | ||
|
||
namespace Paramore.Brighter.Tests.MessagingGateway.RMQ | ||
{ | ||
[Trait("Category", "RMQ")] | ||
public class RmqMessageConsumerMultipleTopicTests : IDisposable | ||
{ | ||
private readonly IAmAMessageProducer _messageProducer; | ||
private readonly IAmAMessageConsumer _messageConsumer; | ||
private readonly Message _messageTopic1, _messageTopic2; | ||
private readonly TestRMQListener _client; | ||
|
||
public RmqMessageConsumerMultipleTopicTests() | ||
{ | ||
_messageTopic1 = new Message(new MessageHeader(Guid.NewGuid(), "test1", MessageType.MT_COMMAND), new MessageBody("test content for topic test 1")); | ||
_messageTopic2 = new Message(new MessageHeader(Guid.NewGuid(), "test2", MessageType.MT_COMMAND), new MessageBody("test content for topic test 2")); | ||
|
||
var rmqConnection = new RmqMessagingGatewayConnection | ||
{ | ||
AmpqUri = new AmqpUriSpecification(new Uri("amqp://guest:guest@localhost:5672/%2f")), | ||
Exchange = new Exchange("paramore.brighter.exchange") | ||
}; | ||
|
||
var topics = new[] {_messageTopic1.Header.Topic, _messageTopic2.Header.Topic}; | ||
|
||
_messageProducer = new RmqMessageProducer(rmqConnection); | ||
_messageConsumer = new RmqMessageConsumer(rmqConnection, "Multiple.Topic.Queue", topics, false, 1, false); | ||
_messageConsumer.Purge(); | ||
|
||
_client = new TestRMQListener(rmqConnection, "Multiple.Topic.Queue", topics); | ||
} | ||
|
||
[Fact] | ||
public void When_reading_a_message_from_a_channel_with_multiple_topics() | ||
{ | ||
_messageProducer.Send(_messageTopic1); | ||
_messageProducer.Send(_messageTopic2); | ||
|
||
var topic1Result = _client.Listen(suppressDisposal: true); | ||
var topic2Result = _client.Listen(); | ||
|
||
|
||
// should_received_a_message_from_test1_with_same_topic_and_body | ||
topic1Result.RoutingKey.Should().Be(_messageTopic1.Header.Topic); | ||
topic1Result.Body.Should().BeEquivalentTo(_messageTopic1.Body.Value); | ||
|
||
// should_received_a_message_from_test2_with_same_topic_and_body | ||
topic2Result.RoutingKey.Should().Be(_messageTopic2.Header.Topic); | ||
topic2Result.Body.Should().BeEquivalentTo(_messageTopic2.Body.Value); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_messageConsumer.Purge(); | ||
_messageProducer.Dispose(); | ||
} | ||
} | ||
} |