Examples

Example 3 .Net C# code example 1 (directly referencing client certificate)

public void Connect()

{

string exchangeName = "scmb"; string hostName = "OneView.domain"; string queueName = "";

string routingKey = "scmb.#";

ConnectionFactory factory = new ConnectionFactory();

factory.AuthMechanisms = new RabbitMQ.Client.AuthMechanismFactory[] { new ExternalMechanismFactory()

};

factory.HostName = hostname; factory.Port = 5671; factory.Ssl.CertPath = @".\scmb.p12"; factory.Ssl.CertPassphrase = "default"; factory.Ssl.ServerName = hostname; factory.Ssl.Enabled = true;

IConnection connection = factory.CreateConnection();

IModel model = connection.CreateModel();

queueName = model.QueueDeclare(queueName, false, false, false, null); model.QueueBind(queueName, exchangeName, routingKey, null);

using (Subscription sub = new Subscription(model, queueName))

{

foreach (BasicDeliverEventArgs ev in sub)

{

DoSomethingWithMessage(ev);

sub.Ack();

}

}

}

Example 4 .Net C# code example 2 (Microsoft Windows certificate store)

public void Connect()

{

string exchangeName = "scmb"; string hostName = "OneView.domain"; string queueName = "";

string routingKey = "scmb.#";

string userName = "rabbitmq_readonly";

X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadWrite);

X509Certificate cert = store.Certificates

.Find(X509FindType.FindBySubjectName, userName, false)

.OfType<X509Certificate>()

.First();

ConnectionFactory factory = new ConnectionFactory();

factory.AuthMechanisms = new RabbitMQ.Client.AuthMechanismFactory[] { new ExternalMechanismFactory()

};

factory.HostName = hostname; factory.Port = 5671;

factory.Ssl.Certs = new X509CertificateCollection(new X509Certificate[] { cert }); factory.Ssl.ServerName = hostname;

factory.Ssl.Enabled = true;

IConnection connection = factory.CreateConnection();

IModel model = connection.CreateModel();

queueName = model.QueueDeclare(queueName, false, false, false, null); model.QueueBind(queueName, exchangeName, routingKey, null);

using (Subscription sub = new Subscription(model, queueName))

{

foreach (BasicDeliverEventArgs ev in sub)

{

DoSomethingWithMessage(ev);

sub.Ack();

}

}

}

190 Using the State-Change Message Bus (SCMB)

Page 190
Image 190
HP OneView manual Examples