forked from BrighterCommand/Brighter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BrighterCommandGH-3386 Fixes unit test & confirm publish
- Loading branch information
Showing
12 changed files
with
65 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#region Licence | ||
|
||
/* The MIT License (MIT) | ||
Copyright © 2014 Ian Cooper <[email protected]> | ||
|
@@ -22,53 +23,50 @@ THE SOFTWARE. */ | |
|
||
#endregion | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Paramore.Brighter.MessagingGateway.RMQ; | ||
using RabbitMQ.Client; | ||
|
||
namespace Paramore.Brighter.RMQ.Tests.MessagingGateway | ||
namespace Paramore.Brighter.RMQ.Tests.MessagingGateway; | ||
|
||
internal class QueueFactory | ||
{ | ||
private readonly RmqMessagingGatewayConnection _connection; | ||
private readonly ChannelName _channelName; | ||
private readonly RoutingKeys _routingKeys; | ||
|
||
internal class QueueFactory | ||
public QueueFactory(RmqMessagingGatewayConnection connection, ChannelName channelName, RoutingKeys routingKeys) | ||
{ | ||
private readonly RmqMessagingGatewayConnection _connection; | ||
private readonly ChannelName _channelName; | ||
private readonly RoutingKeys _routingKeys; | ||
_connection = connection; | ||
_channelName = channelName; | ||
_routingKeys = routingKeys; | ||
} | ||
|
||
public QueueFactory(RmqMessagingGatewayConnection connection, ChannelName channelName, RoutingKeys routingKeys) | ||
{ | ||
_connection = connection; | ||
_channelName = channelName; | ||
_routingKeys = routingKeys; | ||
} | ||
public async Task Create() | ||
{ | ||
var connectionFactory = new ConnectionFactory { Uri = _connection.AmpqUri.Uri }; | ||
await using var connection = await connectionFactory.CreateConnectionAsync(); | ||
await using var channel = | ||
await connection.CreateChannelAsync(new CreateChannelOptions( | ||
publisherConfirmationsEnabled: true, | ||
publisherConfirmationTrackingEnabled: true)); | ||
|
||
public void Create(TimeSpan timeToDelayForCreation) | ||
await channel.DeclareExchangeForConnection(_connection, OnMissingChannel.Create); | ||
await channel.QueueDeclareAsync(_channelName.Value, false, false, false, null); | ||
if (_routingKeys.Any()) | ||
{ | ||
var connectionFactory = new ConnectionFactory {Uri = _connection.AmpqUri.Uri}; | ||
using (var connection = connectionFactory.CreateConnection()) | ||
foreach (RoutingKey routingKey in _routingKeys) | ||
{ | ||
using (var channel = connection.CreateModel()) | ||
{ | ||
channel.DeclareExchangeForConnection(_connection, OnMissingChannel.Create); | ||
channel.QueueDeclare(_channelName.Value, false, false, false, null); | ||
if (_routingKeys.Any()) | ||
{ | ||
foreach (RoutingKey routingKey in _routingKeys) | ||
channel.QueueBind(_channelName.Value, _connection.Exchange.Name, routingKey); | ||
} | ||
else | ||
{ | ||
channel.QueueBind(_channelName.Value, _connection.Exchange.Name, _channelName); | ||
} | ||
|
||
} | ||
await channel.QueueBindAsync(_channelName.Value, _connection.Exchange.Name, routingKey); | ||
} | ||
|
||
//We need to delay to actually create these queues before we send to them | ||
Task.Delay(timeToDelayForCreation).Wait(); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
await channel.QueueBindAsync(_channelName.Value, _connection.Exchange.Name, _channelName); | ||
} | ||
|
||
//We need to delay to actually create these queues before we send to them | ||
// await Task.Delay(timeToDelayForCreation); | ||
} | ||
} |
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
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
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
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