msw10100

msw10100

Conduit Framework - Can I parameterize Conduit.Broker

Is it possible to parameterize a Conduit.Broker?

I have a scenario in which I’d like to be able to launch multiple instances of an app in a single BEAM, and I want each one to have its own broker. The broker (AMQP is the adapter) creates queue bindings based on an identifier of some sort. I’d like to have a single source file for the broker, but parameterize it when it starts up so each instance of it can have its own queue bindings.

Most Liked

msw10100

msw10100

Thanks for the reply! I’ll try to explain why I want to do this.

Work queues are queues that can be serviced by any service instance. They have well-known names, so they don’t need to be parameterized. Any worker instance can subscribe to them to receive messages to perform work bound to those queues.

Example Work Queue Name: “TraceLogger”, which binds to “Framework.TraceLogger.#”, so it receives, any message with a routing key that begins with “Framework.TraceLogger”. Any instance of the TraceLogger service can receive a message from this queue and service that message.

Instance queues are specific to a particular instance of a service. They receive responses to requests made by this service instance. Typically this is for handling responses to RPCs, but may also be used for services that perform some stateful function, like receiving and processing blocks of a file. Once a specific instance of a file transfer service has agreed to process a file transfer, all the blocks of that particular file need to come to this particular service instance.

Example Instance Queue Name: “FileTransfer_52f1b81a”. It binds to “Framework.FileTransfer__52f1b81a.#”. The name is used in the ReplyTo field of a response message and becomes the destination of RPC responses and the destination for individual blocks of a file.

There’s another type of queue, a control queue, which enables our service manager to interact with a specific service instance to perform service management functions. It’s like an instance queue, but it doesn’t bind to application-specific messages, but to service control messages.

  def work_queue_name, do: BrokerConfig.service_name

  def instance_queue_name,  do: BrokerConfig.service_name <>
        "_" <> BrokerConfig.instance_name()

  def work_queue_bindings,  do: BrokerConfig.work_queue_bindings() ++
        [
          "Framework." <> work_queue_name() <> ".#",
          "Framework.SomeOtherAppSpecificMessage" 
        ]

  def instance_queue_bindings, do: BrokerConfig.instance_queue_bindings() ++
        [
          "Framework." <> instance_queue_name() <> ".#"
        ]

  configure do
    queue(&work_queue_name/0, &work_queue_options/0)
    queue(&instance_queue_name/0, &instance_queue_options/0)
  end

  :
  : other broker configuration, pipelines, subscribers, etc...
  : 

So an instance of the service is parameterized with a BrokerConfig struct containing service name, instance name, queue options, etc…

Technically speaking, the queue names aren’t important except for the well-known queue name, but the control and instance bindings are unique per service. That’s what we’re trying to parameterize.

If we want to be able to run multiple instances of a service within a single BEAM instance, we need to be able to instantiate a broker for each one, parameterized with a BrokerConfig.

Each is an independent service, made up of a supervision tree of various Elixir processes. Each creates and binds to an instance queue and a control queue and binds to a pre-existing work queue. Our service management framework starts them and shuts them down dynamically within in an Erlang cluster in response to various scaling or application management criteria.

For example, a file transfer service might have several instances, some of which write files to a high speed store, others of which might write files to a low-speed archive store.

All of the services in our AMQP distributed service fabric implement this protocol of queues with dynamic bindings. Our existing services are written in C#, Python, and C++. We are adding Elixir to the mix.

Possible (somewhat hacky) solution: If we made BrokerConfig a per-BEAM Singleton agent we could use logic that limits us to launching a single service instance at a time and it would parameterize itself from that singleton BrokerConfig. Once it’s launched, we could reset the contents of the BrokerConfig and then launch another instance of the service, which would receive the new parameters.

We could also just abandon our naming conventions and use completely random queue names which don’t require parameterization, but since all the other languages can implement the conventions, and our ops people are used to seeing these names in logfiles and rabbitmq management tools, it would be … unfortunate if our Elixir services couldn’t do it.

I know this is long and presents a particular way of interacting with Rabbit that may not be completely standard. It’s a set of conventions that work well for us. Thanks for reading and considering it all.

Cheers!

msw10100

msw10100

I think that’ll work. I’ll DM you to work out the details and I’ll be happy to work on it.

Thanks!

blatyo

blatyo

Conduit Core Team

Thanks, I’ll come back to this later and read it more carefully. But, here’s what I think we could do that also supports some other cases I’ve had in mind.

Right now, the config for the broker is all specified in the application config. I’d like someone to be able to override that by passing config to start_link. That way, you’d be able to do something like this in a supervisor.

children = [
  {MyApp.Broker, [[config: :override]]}
] 

Additionally, I’d be willing to support passing this config merged with the application config to the name and options functions. This would allow you to specify arbitrary config options and use them for parameterization.

Does that sound like it would work for your case? Would you be willing to work on that?

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement