-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persistent subscriptions and clustered eventstore. #84
Comments
I haven't tried this locally yet but my guess is that EventStore doesn't let you create persistent subscriptions from follower members of a cluster. You could inspect the list of cluster members with |
Thank you for your response!
That is correct and indeed what i ended up doing. But since the leader information is available in the headers of the error response it would save some api calls if they was exposed, would you be willing to accept a PR that exposes them? :) |
Yeah, avoiding a round trip for this sounds like a nice improvement! Go ahead and open up a PR 👍 |
I ran into this same issue while using Commanded with the Spear adapter. I'm an elixir noob, so there could be a better way to do this, but I start a Spear.Connection, call cluster_info to determine the leader, then rewrite the Commanded.Application configuration using the correct host and port. defp connect_to_leader(module) do
app_conf = module.config()
spear_conf = get_in(app_conf, [:event_store, :spear])
{:ok, spear} = Spear.Connection.start_link(Keyword.put(spear_conf, :name, LeaderNodeLocator))
{:ok, nodes} = Spear.cluster_info(spear)
[%Spear.ClusterMember{address: address, port: port}] = Enum.filter(nodes, fn node -> node.state == :Leader end)
leader_conn_str = Regex.replace(~r/@.*\/?\?/, spear_conf |> Keyword.get(:connection_string), "@#{address}:#{port}?")
leader_app_conf =
Keyword.update!(app_conf, :event_store, fn event_store_conf ->
Keyword.update!(event_store_conf, :spear, fn spear_conf ->
Keyword.put(spear_conf, :connection_string, leader_conn_str)
end)
end)
GenServer.call(spear, :close)
GenServer.stop(spear)
{module, leader_app_conf}
end |
Hello!
I am trying to use
spear
create/connect to persistent subscriptions in a clustered eventstoredb setup.If the
Spear.Connection
is connected to a non-leader node an error like this is returned, which contains the info needed to re-connect to the leader node:The call to
Spear.create_persistent_subscription
returns an error like this, which was very confusing to me at first:I was able to reproduce the issue by switching the docker setup in the
spear
repo to use a clustered eventstoredb, and with some additional logging i get this:edit:
I accidentally submitted this issue before i was done writing it.
Is there recomended way to handle this? Look up leader before creating the subscription? or is this a bug?
The text was updated successfully, but these errors were encountered: