Ejemplo n.º 1
0
        // [Obsolete(error:true,message:"Yeah, this won't work yet")]
        //public async Task ix(this IServiceCollection sc)
        // {
        //     var eventName = "T";//TEvent.GetType().Name.Replace(EVENT_SUFFIX, "");
        //    // sc.

        //     await client.SubAsync(eventName, stream => stream.Subscribe(msg => {
        //         // msg.FromJson()
        //         msg.FromJson(eventName);
        //        //Console.WriteLine($"Clock ticked. Tick is {msg.GetPayloadAsString()}");
        //     }));

        //     //await client.SubAsync<TEvent>(eventName,msg => {
        //     //    msg.
        //     //}
        // }

        public async Task Publish <TEvent>(params TEvent[] events)
            where TEvent : class, IEvent
        {
            foreach (var @event in events)
            {
                var eventName = @event.GetType().Name.Replace(EVENT_SUFFIX, "");
                client.PubAsJson <TEvent>(eventName, @event);
            }
        }
        public void Should_be_able_to_publish_and_consume_JSON_payloads_synchronously()
        {
            var orgItem = EncodingTestItem.Create();
            EncodingTestItem decodedItem = null;

            _client.Sub("ClientProtobufEncodingTests", stream => stream.Subscribe(msg =>
            {
                decodedItem = msg.FromJson <EncodingTestItem>();
                ReleaseOne();
            }));

            _client.PubAsJson("ClientProtobufEncodingTests", orgItem);
            WaitOne();

            orgItem.Should().BeEquivalentTo(decodedItem);
        }
        public async Task Should_be_able_to_publish_and_consume_JSON_payloads_synchronously()
        {
            var subject = Context.GenerateSubject();
            var orgItem = EncodingTestItem.Create();
            EncodingTestItem decodedItem = null;

            _sync   = Sync.MaxOne();
            _client = await Context.ConnectClientAsync();

            _client.Sub(subject, stream => stream.Subscribe(msg =>
            {
                decodedItem = msg.FromJson <EncodingTestItem>();
                _sync.Release();
            }));

            _client.PubAsJson(subject, orgItem);
            _sync.WaitForAll();

            orgItem.Should().BeEquivalentTo(decodedItem);
        }