我已成功创建与AWS SQS的连接。这是我的代码:
def start_link(_opts) do
Broadway.start_link(__MODULE__,
name: __MODULE__,
producers: [
default: [
module: {
BroadwaySQS.Producer,
queue_name: "my_queue",
config: [
access_key_id: "key",
secret_access_key: "secret",
region: "ap-south-1"
]
},
stages: 60
]
],
processors: [
default: [
stages: 100
]
],
batchers: [
default: [
stages: 80,
batch_size: 10,
batch_timeout: 2000
]
]
)
end
# callbacks
def handle_message(_, %Message{data: data} = message, _) do
message
|> Message.update_data(fn data -> data * data end)
end
def handle_message(_, message, _) do
receipt = %{
id: message.metadata.message_id,
receipt_handle: message.metadata.receipt_handle
}
IO.inspect(receipt)
# Do something with the receipt
end
def handle_batch(_, messages, _, _) do
list = messages |> Enum.map(fn e -> e.data end)
IO.inspect(list, label: "Got batch from SQS")
messages
end
我是长生不老药的新开发者。谁能帮助我有关如何从AWS SQS发送和接收消息的信息。 handle_batch和handle_message函数的目的是什么。如果这是幼稚的问题,请原谅我。
答案 0 :(得分:1)
有一本关于初学者的百老汇真棒文章:https://akoutmos.com/post/broadway-rabbitmq-and-the-rise-of-elixir/。它有RabbitMQ示例,但也许您可以对SQS使用相同的想法
如前所述,百老汇中没有“发送”部分,因为它更像是一个消费消息的框架