Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Seq.Input.RabbitMQ/RabbitMQInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public class RabbitMQInput : SeqApp, IPublishJson, IDisposable
HelpText = "Whether or not messages should be auto-acknowledged. The default is true.")]
public bool IsReceiveAutoAck { get; set; } = true;

[SeqAppSetting(
DisplayName = "Dead Letter Exchange",
IsOptional = true,
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.")]
public string Dlx { get; set; }

public void Start(TextWriter inputWriter)
{
var sync = new object();
Expand Down Expand Up @@ -111,7 +117,8 @@ void Receive(ReadOnlyMemory<byte> body)
IsQueueDurable,
IsQueueAutoDelete,
IsQueueExclusive,
IsReceiveAutoAck);
IsReceiveAutoAck,
Dlx);
}

public void Stop()
Expand Down
23 changes: 14 additions & 9 deletions src/Seq.Input.RabbitMQ/RabbitMQListener.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net.Security;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
Expand All @@ -10,19 +11,19 @@ class RabbitMQListener : IDisposable
readonly IConnection _connection;
readonly IModel _channel;

public RabbitMQListener(
Action<ReadOnlyMemory<byte>> receive,
public RabbitMQListener(Action<ReadOnlyMemory<byte>> receive,
string rabbitMQHost,
string rabbitMQVHost,
int rabbitMQPort,
string rabbitMQUser,
int rabbitMQPort,
string rabbitMQUser,
string rabbitMQPassword,
string rabbitMQQueue,
string rabbitMQQueue,
bool isSsl,
bool isQueueDurable,
bool isQueueAutoDelete,
bool isQueueDurable,
bool isQueueAutoDelete,
bool isQueueExclusive,
bool isReceiveAutoAck)
bool isReceiveAutoAck,
string dlx)
{
var factory = new ConnectionFactory
{
Expand All @@ -40,12 +41,16 @@ public RabbitMQListener(
_connection = factory.CreateConnection();
_channel = _connection.CreateModel();

var arguments = string.IsNullOrWhiteSpace(dlx)
? null
: new Dictionary<string, object> { {"x-dead-letter-exchange", dlx} };

_channel.QueueDeclare(
rabbitMQQueue,
durable: isQueueDurable,
exclusive: isQueueExclusive,
autoDelete: isQueueAutoDelete,
arguments: null);
arguments: arguments);

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