Exemplo n.º 1
0
        public void Publish(IntegrationEvent @event)
        {
            var env = AppConfigUtilities.GetAppConfig <string>("KAFKA_ENV");


            var eventName = @event.GetType().Name;
            var kafkaUrl  = AppConfigUtilities.GetAppConfig <string>("KAFKA_URL");
            var config    = new ProducerConfig {
                BootstrapServers = kafkaUrl
            };
            var topic = env + eventName;

            if (@event.AggregateId.IsNullOrEmpty())
            {
                @event.AggregateId = Guid.NewGuid().ToString();
            }
            var msg = new Message <string, string> {
                Key = @event.AggregateId, Value = @event.ToJSON()
            };

            using (var p = new ProducerBuilder <string, string>(config).Build())
            {
                var result = p.ProduceAsync(topic, msg).Result;

                _EventStore.Persist(@event, result.Offset.Value);
            }
        }
Exemplo n.º 2
0
        public void Publish(IntegrationEvent @event)
        {
            var env = AppConfigUtilities.GetAppConfig <string>("KAFKA_ENV");

            _EventStore.Persist(@event);

            var _config = new Config();

            var eventName = @event.GetType().Name;

            using (Producer producer = new Producer(_config, AppConfigUtilities.GetAppConfig <string>("KAFKA_URL")))

                using (Topic topic = producer.Topic(env + eventName))
                {
                    var            id             = Encoding.UTF8.GetBytes(@event.AggregateId);
                    byte[]         data           = Encoding.UTF8.GetBytes(@event.ToJSON());
                    DeliveryReport deliveryReport = topic.Produce(data, id).Result;
                }
        }