Skip to content

Commit 6619f9f

Browse files
authored
Merge pull request #7 from antoniaelek/feature/dlx
Added dlx parameter.
2 parents 7f6b505 + ca6425b commit 6619f9f

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/Seq.Input.RabbitMQ/RabbitMQInput.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ public class RabbitMQInput : SeqApp, IPublishJson, IDisposable
8080
HelpText = "Whether or not messages should be auto-acknowledged. The default is true.")]
8181
public bool IsReceiveAutoAck { get; set; } = true;
8282

83+
[SeqAppSetting(
84+
DisplayName = "Dead Letter Exchange",
85+
IsOptional = true,
86+
HelpText = "The name of the dead letter exchange associated with this queue. If specified, the exchange will be used when declaring the queue, otherwise no dead lettering will be configured.")]
87+
public string Dlx { get; set; }
88+
8389
public void Start(TextWriter inputWriter)
8490
{
8591
var sync = new object();
@@ -111,7 +117,8 @@ void Receive(ReadOnlyMemory<byte> body)
111117
IsQueueDurable,
112118
IsQueueAutoDelete,
113119
IsQueueExclusive,
114-
IsReceiveAutoAck);
120+
IsReceiveAutoAck,
121+
Dlx);
115122
}
116123

117124
public void Stop()

src/Seq.Input.RabbitMQ/RabbitMQListener.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Net.Security;
34
using RabbitMQ.Client;
45
using RabbitMQ.Client.Events;
@@ -10,19 +11,19 @@ class RabbitMQListener : IDisposable
1011
readonly IConnection _connection;
1112
readonly IModel _channel;
1213

13-
public RabbitMQListener(
14-
Action<ReadOnlyMemory<byte>> receive,
14+
public RabbitMQListener(Action<ReadOnlyMemory<byte>> receive,
1515
string rabbitMQHost,
1616
string rabbitMQVHost,
17-
int rabbitMQPort,
18-
string rabbitMQUser,
17+
int rabbitMQPort,
18+
string rabbitMQUser,
1919
string rabbitMQPassword,
20-
string rabbitMQQueue,
20+
string rabbitMQQueue,
2121
bool isSsl,
22-
bool isQueueDurable,
23-
bool isQueueAutoDelete,
22+
bool isQueueDurable,
23+
bool isQueueAutoDelete,
2424
bool isQueueExclusive,
25-
bool isReceiveAutoAck)
25+
bool isReceiveAutoAck,
26+
string dlx)
2627
{
2728
var factory = new ConnectionFactory
2829
{
@@ -40,12 +41,16 @@ public RabbitMQListener(
4041
_connection = factory.CreateConnection();
4142
_channel = _connection.CreateModel();
4243

44+
var arguments = string.IsNullOrWhiteSpace(dlx)
45+
? null
46+
: new Dictionary<string, object> { {"x-dead-letter-exchange", dlx} };
47+
4348
_channel.QueueDeclare(
4449
rabbitMQQueue,
4550
durable: isQueueDurable,
4651
exclusive: isQueueExclusive,
4752
autoDelete: isQueueAutoDelete,
48-
arguments: null);
53+
arguments: arguments);
4954

5055
var consumer = new EventingBasicConsumer(_channel);
5156
consumer.Received += (model, ea) => receive(ea.Body);

0 commit comments

Comments
 (0)