Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/64j0/fsharp-rabbitmq
Simple projects that illustrates how one can use F# along with RabbitMQ to send and receive messages
https://github.com/64j0/fsharp-rabbitmq
fsharp rabbitmq
Last synced: about 1 month ago
JSON representation
Simple projects that illustrates how one can use F# along with RabbitMQ to send and receive messages
- Host: GitHub
- URL: https://github.com/64j0/fsharp-rabbitmq
- Owner: 64J0
- Created: 2024-03-07T01:14:32.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-03-09T21:18:09.000Z (8 months ago)
- Last Synced: 2024-10-12T21:03:07.216Z (about 1 month ago)
- Topics: fsharp, rabbitmq
- Language: F#
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# F# + RabbitMQ
This repository holds a simple project that illustrates how one can use F# along with RabbitMQ to send and receive messages. It is 100% based on the RabbitMQ [Get Started documentation for .NET](https://www.rabbitmq.com/tutorials/tutorial-one-dotnet).
For an older version you can check this other repository [edgarsanchez/FsRabbitMQ-Tutorials](https://github.com/edgarsanchez/FsRabbitMQ-Tutorials).
I'm adding my notes while studying RabbitMQ documentation to [this document](./NOTES.md). Hope it's useful to understand this tool and most of the code here.
## How to use?
First, make sure that you have started the RabbitMQ container and restored the packages with:
```bash
docker-compose up -ddotnet restore
```Now you can start looking for the example instructions.
### Basic example:
```bash
# 1. run the Receive/ project
# our consumer
dotnet run --project Receive/# 2. run the Send/ project
# our publisher
dotnet run --project Send/
```### Work-queue pattern
Each task is delivered to exactly one worker:
```bash
# 1.1. run the Worker/ project
# our consumer 1
dotnet run --project Worker/# 1.2. run the Worker/ project
# our consumer 2
dotnet run --project Worker/# 2. run the NewTask/ project
# our publisher
dotnet run --project NewTask/ "First message."
dotnet run --project NewTask/ "Second message.."
dotnet run --project NewTask/ "Third message..."
dotnet run --project NewTask/ "Fourth message...."# notice that the messages are distributed according to round-robin
# through our worker instances
```### Publish/subscribe pattern
Deliver a message to multiple consumers using a `fanout` exchange:
```bash
# 1.1 run the ReceiveLogs/ project
dotnet run --project ReceiveLogs/# 1.2 run the ReceiveLogs/ project
dotnet run --project ReceiveLogs/# 2. run the EmitLog/ project
dotnet run --project EmitLog/ "First message."
dotnet run --project EmitLog/ "Second message.."
dotnet run --project EmitLog/ "Third message..."
dotnet run --project EmitLog/ "Fourth message...."
```### Publish/subscribe pattern 2
Deliver a message to multiple consumers, but limit some consumers to a subset of all the messages (`direct` exchange) using QueueBinding `routingKey`:
```bash
# 1 run the ReceiveLogsDirect/ project
dotnet run --project ReceiveLogsDirect/# 2. run the EmitLogDirect/ project
dotnet run --project EmitLogDirect/ error "First message."
dotnet run --project EmitLogDirect/ info "Second message.."
dotnet run --project EmitLogDirect/ warning "Third message..."
dotnet run --project EmitLogDirect/ error "Fourth message...."
```### Publish/subscribe pattern 3
Deliver a message to multiple consumers, but limit some consumers to a subset of all the messages (`topic` exchange) using QueueBinding `routingKey` and the message source:
```bash
# 1 run the ReceiveLogsTopic/ project
dotnet run --project ReceiveLogsTopic/ "#"
dotnet run --project ReceiveLogsTopic/ "kern.*"
dotnet run --project ReceiveLogsTopic/ "*.critical"# 2. run the EmitLogTopic/ project
dotnet run --project EmitLogTopic/ "kern.critical" "A critical kernel error"
dotnet run --project EmitLogTopic/ "kern.critical" "Run!"
```### RPC calls
Running a function on a remote process and wait for the result.
In general doing RPC over RabbitMQ is easy. A client sends a request message and a server replies with a response message. In order to receive a response we need to send a 'callback' queue address with the request.
```bash
# 1 run the RPCServer/
dotnet run --project RPCServer/# 2 run the RPCClient/
dotnet run --project RPCClient/
```