🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 4 Min Lesezeit
0

RabbitMQ - Fanout Exchange Pattern.

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Hi devs



The Fanout Exchange Pattern is one of the most commonly used messaging patterns in RabbitMQ. It's perfect for scenarios where a message needs to be sent to multiple consumers simultaneously. In this post, we'll dive into what the Fanout Exchange is, how it works, and how to implement it in a real-world example using RabbitMQ and .NET.









What is a Fanout Exchange?



A Fanout Exchange is a type of exchange in RabbitMQ that broadcasts messages to all queues bound to it, regardless of the routing key. This is useful for:




  • Broadcasting events like system-wide notifications or updates.

  • Workflows where multiple services must act upon the same event.

  • Pub/Sub architectures where multiple subscribers listen to a single publisher.









How Does It Work?




  1. A producer sends a message to a fanout exchange.

  2. The exchange routes the message to all bound queues.

  3. Each queue has one or more consumers that process the messages.



Key Features:





  • No routing key is required for message delivery.

  • Messages are delivered to all bound queues, ensuring parallel processing.









Example Use Case



Imagine a payment system where multiple services need to act on a PaymentCompleted event:





  1. Notification Service: Sends a payment receipt to the customer.


  2. Analytics Service: Updates financial dashboards.


  3. Inventory Service: Restocks sold items.



Each of these services will consume the same event from the fanout exchange.









Implementing the Fanout Exchange Pattern



Let’s build a simple example with a producer and two consumers using RabbitMQ in .NET.






1. Set Up RabbitMQ



Install RabbitMQ locally or use Docker:




CODE
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:management






Access the RabbitMQ management UI at http://localhost:15672 (default credentials: guest/guest).









2. Producer: Publish Messages to the Fanout Exchange






CODE
using RabbitMQ.Client;
using System.Text;

public class PaymentProducer
{
public void PublishPaymentCompletedEvent(string paymentId)
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();

// Declare a fanout exchange
channel.ExchangeDeclare(exchange: "payments_exchange", type: ExchangeType.Fanout);

var message = $"Payment completed: {paymentId}";
var body = Encoding.UTF8.GetBytes(message);

// Publish message to the exchange
channel.BasicPublish(exchange: "payments_exchange", routingKey: "", body: body);
Console.WriteLine($"Published: {message}");
}
}

// Usage
var producer = new PaymentProducer();
producer.PublishPaymentCompletedEvent("12345");






This code declares a fanout exchange called payments_exchange and publishes a PaymentCompleted message to it.









3. Consumer 1: Notification Service






CODE
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System.Text;

public class NotificationConsumer
{
public void Start()
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();

// Declare the exchange and a unique queue
channel.ExchangeDeclare(exchange: "payments_exchange", type: ExchangeType.Fanout);
var queueName = channel.QueueDeclare().QueueName;
channel.QueueBind(queue: queueName, exchange: "payments_exchange", routingKey: "");

var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body.ToArray();
var message = Encoding.UTF8.GetString(body);
Console.WriteLine($"[Notification Service] Received: {message}");
};

channel.BasicConsume(queue: queueName, autoAck: true, consumer: consumer);
Console.WriteLine("Notification Service is running...");
}
}

// Usage
var notificationConsumer = new NotificationConsumer();
notificationConsumer.Start();












4. Consumer 2: Analytics Service






CODE
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System.Text;

public class AnalyticsConsumer
{
public void Start()
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();

// Declare the exchange and a unique queue
channel.ExchangeDeclare(exchange: "payments_exchange", type: ExchangeType.Fanout);
var queueName = channel.QueueDeclare().QueueName;
channel.QueueBind(queue: queueName, exchange: "payments_exchange", routingKey: "");

var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body.ToArray();
var message = Encoding.UTF8.GetString(body);
Console.WriteLine($"[Analytics Service] Received: {message}");
};

channel.BasicConsume(queue: queueName, autoAck: true, consumer: consumer);
Console.WriteLine("Analytics Service is running...");
}
}

// Usage
var analyticsConsumer = new AnalyticsConsumer();
analyticsConsumer.Start();












Testing the Setup




  1. Run NotificationConsumer and AnalyticsConsumer.

  2. Publish a message using PaymentProducer.

  3. Both consumers should receive the message and process it independently.









Key Advantages of the Fanout Exchange Pattern





  1. Scalable: Easily add more consumers without changing the producer.


  2. Decoupled Communication: Producers don’t need to know about consumers.


  3. Parallel Processing: Multiple services can act on the same message simultaneously.


  4. Flexibility: Supports broadcasting and real-time updates.









Conclusion



The Fanout Exchange Pattern is a powerful way to broadcast messages to multiple services in a microservices architecture. It’s simple to implement with RabbitMQ and provides scalability and decoupled communication.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten RabbitMQ - Fanout Exchange Pattern.

Thematisch verwandte Begriffe: RabbitMQ, Fanout, Exchange, Pattern · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...