Esempio n. 1
0
        private static async Task SendNotification(PayloadDetails payloadDetails)
        {
            string brokerList       = ConfigurationManager.AppSettings["EH_FQDN"];
            string connectionString = ConfigurationManager.AppSettings["EH_CONNECTION_STRING"];
            string topic            = ConfigurationManager.AppSettings["EH_NAME"];
            string caCertLocation   = ConfigurationManager.AppSettings["CA_CERT_LOCATION"];

            await Worker.Producer(brokerList, connectionString, topic, caCertLocation, payloadDetails);
        }
Esempio n. 2
0
        public static async Task Producer(string brokerList, string connStr, string topic, string cacertlocation, PayloadDetails message)
        {
            try
            {
                var config = new Dictionary <string, object> {
                    { "bootstrap.servers", brokerList },
                    { "security.protocol", "SASL_SSL" },
                    { "sasl.mechanism", "PLAIN" },
                    { "sasl.username", "$ConnectionString" },
                    { "sasl.password", connStr },
                    { "ssl.ca.location", cacertlocation },
                    //{ "debug", "security,broker,protocol" }       //Uncomment for librdkafka debugging information
                };

                using (var producer = new Producer <long, string>(config, new LongSerializer(), new StringSerializer(Encoding.UTF8)))
                {
                    Console.WriteLine("- Sending messages to topic: " + topic + ", broker(s): " + brokerList);

                    string msg = JsonConvert.SerializeObject(message);
                    await producer.ProduceAsync(topic, DateTime.UtcNow.Ticks, msg);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("!!! Exception Occurred - {0}", e.Message);
            }
        }