Hulkstance
unread,Oct 23, 2022, 5:37:01 PM10/23/22Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rabbitmq-users
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? There are chain certificates (3 files in total) that I'm not sure there are options for.
## Python
```py
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
```cs
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);
}
```