Subscribing to a stream before it is created

Hi all,

I’m in a situation where I am writing to a stream for all user events but have projections enabled so a stream is created per user id. If a new user is added to the system hence a stream for that user doesn’t exist before I write the first
event, what would happen if I subscribed to that non-existent stream—I need to wait for an event to be written to the new users stream before returning to the caller, is this possible?

Any help appreciated.

Kind regards

Sean.

Sean,

I hit the same problem and as far as I know (happy to be wrong) the stream has to be there.

My “ConnectToSubscription” method is like this:

        try
        {
            await connectToPersistentSubscriptionAsync();
        }
        catch(Exception e)
        {
            if (e.InnerException != null && e.InnerException.Message == "Subscription not found")
            {
                //Create the Group
                await this.CreatePersistentSubscriptionFromBeginningAsync(stream, groupName);

                await connectToPersistentSubscriptionAsync();
            }
            else
            {
                throw;
            }
        }

``

What kind of subscription?

Hi,

Probably a persistent subscripting, although I'm looking at a cachup, so any advice would be appreciated.
Kind regards
Sean.

For either you should be able to just set metadata on the original
stream (eg set {foo : bar} etc and they should work. I believe catchup
can work without this (will retry) but would need to test