Skip to content

Added dlx parameter. #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 = "Name of dead letter exchange associated with this queue.")]
public string Dlx { get; set; } = "guest";

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