public async Task Publish <T>(string publishedLanguageEntity, T message, long sequence)
        {
            var envelope = new Envelope <T>(_boundedContextName, message, sequence);
            var msgBytes = System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(envelope);

            var topic = _session.GetTopic($"topic://{NamingConventions.Topic(_boundedContextName, publishedLanguageEntity)}");

            //var msg = _producer.CreateBytesMessage(msgBytes);
            var msg = _producer.CreateTextMessage(System.Text.Json.JsonSerializer.Serialize(envelope));

            _producer.Send(topic, msg, MsgDeliveryMode.Persistent, MsgPriority.Normal, TimeSpan.FromMinutes(5));
        }
Ejemplo n.º 2
0
        public async Task <IDisposable> AddSubscription <TEvent>(string sourceBoundedContextName, string publishedLanguageEntity)
            where TEvent : class
        {
            var topic    = _session.GetTopic($"topic://{NamingConventions.Topic(sourceBoundedContextName, publishedLanguageEntity)}");
            var consumer = _session.CreateConsumer(topic);

            consumer.Listener += async msg => await OnMessage <TEvent>(msg);

            if (!_conn.IsStarted)
            {
                _conn.Start();
            }
            return(consumer);
        }