private Task <IEventStream> SubscribeAsync(
            IServiceProvider services,
            EventDescription @event)
        {
            IEventRegistry eventRegistry =
                (IEventRegistry)services.GetService(typeof(IEventRegistry));

            if (eventRegistry == null)
            {
                throw new QueryException(new QueryError(
                                             "Register a event registry as service in order " +
                                             "to use subsciptions."));
            }

            return(eventRegistry.SubscribeAsync(@event));
        }
        private static async ValueTask <IAsyncEnumerable <object> > DefaultSubscribeResolverAsync(
            IResolverContext resolverContext)
        {
            EventDescription eventDescription = CreateEvent(resolverContext);
            IServiceProvider services         = resolverContext.Service <IServiceProvider>();
            IEventRegistry   eventRegistry    = services.GetService <IEventRegistry>();

            if (eventRegistry == null)
            {
                throw new QueryException(
                          ErrorBuilder.New()
                          .SetMessage(CoreResources.SubscriptionExecutionStrategy_NoEventRegistry)
                          .Build());
            }

            return(await eventRegistry.SubscribeAsync(eventDescription));
        }
Example #3
0
        public Task SubscribeOneConsumer_SendMessage_ConsumerReceivesMessage()
        {
            return(TryTest(async() =>
            {
                // arrange
                var cts = new CancellationTokenSource(30000);
                var eventDescription = new EventDescription(
                    Guid.NewGuid().ToString());

                // act
                IEventStream consumer = await _registry
                                        .SubscribeAsync(eventDescription);
                var outgoing = new EventMessage(eventDescription, "bar");
                await _sender.SendAsync(outgoing);

                // assert
                IEventMessage incoming = await consumer.ReadAsync(cts.Token);
                Assert.Equal(outgoing.Payload, incoming.Payload);
            }));
        }