mick
Connecting to Azure Service Bus with rabbitmq-amqp1.0-client
Has anyone had any success connecting to Azure Service Bus with rabbitmq-amqp1.0-client? I’m trying with:
conf = %{
address: "[namespace].servicebus.windows.net",
container_id: "test_container",
port: 5672,
sasl: {:plain, "[keyname]", "[keyvalue"}
}
:amqp10_client.open_connection conf
but keep getting:
{:error, {:shutdown, {:failed_to_start_child, :reader, :badarg}}}
I’ve also tried with an additional tls_opts: {5671} but get the same result.
Mick
Most Liked
shankardevy
@mick if you are still after this, you could try this code. It works for me:
conf = %{
:container_id => <<"test-container">>,
:address => 'abc-shankardevy.servicebus.windows.net',
:port => 5671,
:hostname => <<"abc-shankardevy.servicebus.windows.net">>,
:tls_opts => {:secure_port,[]},
:sasl =>
{:plain,<<"QUEUENAME">>,
<<"keykey">>},
:transfer_limit_margin => 100
}
{:ok, conn} = :amqp10_client.open_connection(conf)
{:ok, session} = :amqp10_client.begin_session(conn)
{:ok, sender } = :amqp10_client.attach_sender_link(session, "test-sender", "command")
out_msg = :amqp10_msg.new("my-tag", "my-body", false)
ok = :amqp10_client.send_msg(sender, out_msg)
slashmili
There has been some improvements, rabbitmq team has pushed amqp10_client to hex. it’s easier to include it to your project.
if you are given a connection string like:
Endpoint=sb://[namespace].servicebus.windows.net/;SharedAccessKeyName=MyKeyName;SharedAccessKey=MyAccessKey;EntityPath=MyEntityPath
Then you can use it in your project like
address = '[namespace].servicebus.windows.net'
hostname = to_string(address)
user = "MyKeyName"
password = "MyAccessKey"
port = 5671
queue_name = "MyEntityPath"
subscription_name = "MySubscriptionName" # This is not provided in the connection string but is an important value. With an invalid setting, you'll get "The messaging entity '....' could not be found.
opn_conf = %{
address: address,
hostname: hostname,
port: port,
container_id: subscription_name,
sasl: {:plain, user, password},
tls_opts: {:secure_port, []},
transfer_limit_margin: 100
}
{:ok, connection} = :amqp10_client.open_connection(opn_conf)
{:ok, session} = :amqp10_client.begin_session(connection)
{:ok, receiver} =
:amqp10_client.attach_receiver_link(
session,
subscription_name,
queue_name
)
:ok = :amqp10_client.flow_link_credit(receiver, 5, :never)
With this code snippet, the messages are sent to the caller’s process mailbox. For more advance usage checkout the source code
if you run it in iex, you can get the messages by running flush:
iex(1)> MyApp.run
iex(2)> flush
{:amqp10_event, {:connection, #PID<0.230.0>, :opened}}
{:amqp10_event, {:session, #PID<0.241.0>, :begun}}
{:amqp10_event, {:link, {:link_ref, :receiver, #PID<0.241.0>, 0}, :attached}}
slashmili
A shameless plug! We have built a Broadway Producer for AMQP1.0 which simplifies lots of low level details, if you are already a Broadway user, highly recommend to try it out.
Last Post!
jan-mb-me
Hello @slashmili, Do you happen to know how to configure a consumer using Kaffe (or another Kafka client library) with the details from such an Azure event hub connection string? I wonder how to split the connection string to provide all required options like :endpoints, :topics, and maybe/probably(?) :sasl (as tried here: klarna/brod with azure/event hub. How to Set up? ).
Alternatively: Can I connect to any Azure Event Hub using amqp10_client or does the Event Hub have to be configured in a specific way to serve as RabbitMQ source instead of a Kafka Producer?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









