예제 #1
0
        public async Task <IMessageResponse> ProduceAsync <TKey, TPayload>(TKey key, IMessage <TPayload> message)
        {
            var cfg = _messageConfigProvider.GetMessageConfiguration(message.MessageType);

            var producer = _schemaProducerFactory.GetSerializingProducer <TKey, TPayload>(cfg.Schema, cfg.Topic);
            var t        = await producer.ProduceAsync(cfg.Topic, key, message.Data);

            return(new MessageResponse
            {
                Successful = !t.Error.HasError,
                ResponseCode = (int)t.Error.Code,
                Response = t.Error.Reason
            });
        }
예제 #2
0
        public IProducer GetProducer(string messageType)
        {
            var transportType = _messageConfigProvider.GetMessageConfiguration(messageType).TransportType;
            var list          = _factory(typeof(IProducer));

            return(FindProducer(list, transportType) as IProducer);
        }
예제 #3
0
        public async Task <IMessageResponse> ProduceAsync <TPayload>(IMessage <TPayload> message)
        {
            var cfg = _messageConfigProvider.GetMessageConfiguration(message.MessageType);

            var messOut = new MessageResponse();

            using (var client = GetHttpClient())
            {
                var httpContent = new StringContent(JsonConvert.SerializeObject(message.Data), Encoding.UTF8, "application/json");
                var resp        = await client.PostAsync(cfg.Endpoint, httpContent);

                messOut.Successful   = (int)resp.StatusCode == 200;
                messOut.ResponseCode = (int)resp.StatusCode;
                messOut.Response     = await resp.Content.ReadAsStringAsync();
            }

            return(messOut);
        }