Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Swift code for RabbitMQ tutorials

Swift code examples for the RabbitMQ tutorials.

These tutorials use BunnySwift, a modern Swift 6 RabbitMQ client with async/await support.

Requirements

  • Swift 6.0 or later
  • macOS 14+ (or iOS 17+, tvOS 17+, watchOS 10+, visionOS 1+)
  • A running RabbitMQ server on localhost

Building

Build all tutorials:

swift build

Running the Tutorials

Tutorial 1: Hello World

In one terminal, start the receiver:

swift run Receive

In another terminal, send a message:

swift run Send

Tutorial 2: Work Queues

Start one or more workers:

swift run Worker

Send tasks with varying workloads (dots indicate seconds of work):

swift run NewTask "A simple task."
swift run NewTask "A longer task..."
swift run NewTask "A very long task....."

Tutorial 3: Publish/Subscribe

Start one or more log receivers:

swift run ReceiveLogs

Emit log messages:

swift run EmitLog "Hello subscribers!"

Tutorial 4: Routing

Subscribe to specific severity levels:

swift run ReceiveLogsDirect error warning

Emit logs with severity:

swift run EmitLogDirect info "Just an info message"
swift run EmitLogDirect warning "This is a warning"
swift run EmitLogDirect error "This is an error!"

Tutorial 5: Topics

Subscribe using topic patterns (* matches one word, # matches zero or more):

swift run ReceiveLogsTopic "kern.*"
swift run ReceiveLogsTopic "*.critical"
swift run ReceiveLogsTopic "#"

Emit logs with topic routing keys:

swift run EmitLogTopic "kern.info" "Kernel info"
swift run EmitLogTopic "kern.critical" "Kernel critical error"
swift run EmitLogTopic "auth.critical" "Authentication failure"

Tutorial Source Files

Tutorial Producer Consumer
1. Hello World Send Receive
2. Work Queues NewTask Worker
3. Pub/Sub EmitLog ReceiveLogs
4. Routing EmitLogDirect ReceiveLogsDirect
5. Topics EmitLogTopic ReceiveLogsTopic