I'm trying to convert the following RabbitMQ Producer over SSL code from Python to C#. I'm not sure how I can specify all these configurations for the certificates. How do I do that?
I read this StackOverflow question, but this python code uses chain of certs.
Python
context = ssl.create_default_context(cafile="./ca.pem")
context.load_cert_chain("./cp_certificate.pem", "./cp_key.pem")
ssl_options = pika.SSLOptions(context, "localhost")
credential = pika.PlainCredentials('rabbitmq', 'rabbitmq!QAZ')
conn_params = pika.ConnectionParameters(host="90.44.213.24", port=5671, ssl_options=ssl_options, credentials=credential, virtual_host='op_vhost')
connection = pika.BlockingConnection(conn_params)
channel = connection.channel()
channel.basic_publish(exchange='custom_flow', routing_key='custom_routing', body='body', mandatory=True)
Current C# code
using System.Text;
using System.Text.Json;
using RabbitMQ.Client;
var factory = new ConnectionFactory
{
HostName = "localhost",
Port = 5671,
Ssl = new SslOption
{
Enabled = true,
ServerName = "localhost"
}
};
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
channel.ExchangeDeclare("custom_flow", ExchangeType.Direct, arguments: null);
var count = 0;
while (true)
{
var message = new
{
Name = "Producer",
Message = $"Hello! Count: {count}"
};
var body = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(message));
channel.BasicPublish("custom_flow", "custom_routing", null, body);
count++;
Console.WriteLine($"Sent message: {message}");
Thread.Sleep(1000);
}