beautypg.com

5 java code example, Prerequisites – HP OneView User Manual

Page 220

background image

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

Prerequisite

Import the scmb.crt into your preferred Windows certificate store.

Example

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()
.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();
}
}
}

NOTE:

.Net C# code example 2 (Microsoft Windows certificate store) is referencing the Trusted

Root Certificate Authorities

store, located under Local Computer.

StoreName.Root

= Trusted Root Certificate Authorities

StortLocation.LocalMachine

= Local Computer

30.5 Java code example

The Java code example shows how to connect and subscribe to the SCMB.

Prerequisites

1.

Download the client certificate and private key.

GET /rest/certificates/client/rabbitmq/keypair/default

2.

Save the contents of the client certificate in the response body into a text file named
default-client.crt

.

You must copy and paste everything from -----BEGIN CERTIFICATE----- to -----END
CERTIFICATE-----

, including the dashes, but not including the quotes.

3.

Save the contents of the private key in the response body into a text file named
default-client.key

.

You must copy and paste everything from -----BEGIN RSA PRIVATE KEY----- to
-----END RSA PRIVATE KEY-----

, including the dashes, but not including the quotes.

220 Using the State-Change Message Bus (SCMB)