-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathmain.swift
More file actions
31 lines (26 loc) · 827 Bytes
/
main.swift
File metadata and controls
31 lines (26 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
// RabbitMQ Swift Tutorials
// Tutorial 5: Topics - EmitLogTopic
//
// https://www.rabbitmq.com/tutorials/tutorial-five-swift
//
import BunnySwift
import Foundation
@main
struct EmitLogTopic {
static func main() async throws {
let connection = try await Connection.open()
let channel = try await connection.openChannel()
let exchange = try await channel.topic("topic_logs")
var args = Array(CommandLine.arguments.dropFirst())
let routingKey = args.isEmpty ? "anonymous.info" : args.removeFirst()
let message = args.isEmpty ? "Hello World!" : args.joined(separator: " ")
try await channel.basicPublish(
body: Data(message.utf8),
exchange: exchange.name,
routingKey: routingKey
)
print(" [x] Sent '\(routingKey):\(message)'")
try await connection.close()
}
}