Send message


using RabbitMQ.Client;
using System;
using System.Text;
public partial class Queue
{
    public static void SendMessage(string hostname, int port, string queuename, string username, string password, string message)
    {
        try
        {
            // RabbitMQ server connection parameters
            ConnectionFactory factory = new ConnectionFactory
            {
                HostName = hostname,
                Port = port,
                UserName = username,
                Password = password,
                VirtualHost = "/",
                AutomaticRecoveryEnabled = true,
                TopologyRecoveryEnabled = true,
                ContinuationTimeout = new TimeSpan(1, 0, 0, 0)
            };

            // Create a connection to the RabbitMQ server
            IConnection connection = factory.CreateConnection();

            // Create a channel
            IModel channel = connection.CreateModel();

            // Declare a queue
            channel.QueueDeclare(queuename, true, false, false, null);

            // Publish the message to the queue
            channel.BasicPublish("", queuename, null, Encoding.UTF8.GetBytes(message));
        }
        catch (Exception ex)
        {
            throw new ApplicationException(ex.Message);
        }
    }
}