During the project’s working proccess I get null
in the line: connection = await connectionFactory.CreateAsync(endpoints);
without any Exception. Artemis also does not record any errors during the connection attempts.
I need to create connection with ArtemisMQ, that running on the docker container. Connection must by encrypted by the TLS 1.2. All needed certificates must be located only in Artemis.
.Net client shouldn’t get any certificates, because project project is written on Framework 4.7.2 and will be run using Mono on Linux, and Mono has no support of X509 certificates.
Attempt of sending messages to the same ArtemisMQ by simple TCP using this .net library works correctly.
For creating the connection I use “.NET Client for Apache ActiveMQ Artemis” library.
This code of service, that create ConnectionFactory, Endpoints and ect:
public class AmqMessageBrokerService : IAmqMessageBrokerService
{
private readonly IBrokerConfigSection brokerConfigSection;
private ConnectionFactory connectionFactory;
private List<Endpoint> endpoints = new List<Endpoint>();
private ProducerConfiguration producerConfiguration;
private IConnection connection;
private IProducer producer;
private bool isConnected = false;
public AmqMessageBrokerService(
IBrokerConfigSection brokerConfigSection)
{
this.brokerConfigSection = brokerConfigSection;
connectionFactory = new ConnectionFactory()
{
SSL =
{
ClientCertificates = null,
Protocols = SslProtocols.Tls12,
CheckCertificateRevocation = false,
RemoteCertificateValidationCallback = null,
LocalCertificateSelectionCallback = null
}
};
var endpoint = Endpoint.Create(
host: "localhost",
port: 61617,
user: brokerConfigSection.ArtemisMQUserName,
password: brokerConfigSection.ArtemisMQPassword,
scheme: Scheme.Amqps,
path: brokerConfigSection.ArtemisMQConnectionString);
endpoints.Add(endpoint);
producerConfiguration = new ProducerConfiguration()
{
Address = "MyAdress"
};
}
public async Task StartSendMessagesToAmqAsync(
ISyslogReadQueueManageService syslogReadQueueManageService,
CancellationToken ct)
{
while (!ct.IsCancellationRequested)
{
Thread.Sleep(1000);
Console.WriteLine("Connecting with ArtemisMq is started...n");
var timeoutTask = Task.Delay(10000);
var acceptTask = CreateAmqConnectionAsync();
await Task.WhenAny(timeoutTask, acceptTask);
if (!acceptTask.IsCompleted)
{
continue;
}
await SendMessageToArtemisAsync(
syslogReadQueueManageService,
ct);
}
}
private async Task CreateAmqConnectionAsync()
{
try
{
connection = await connectionFactory.CreateAsync(endpoints);
producer = await connection.CreateProducerAsync(producerConfiguration);
isConnected = true;
Console.WriteLine("Connection with ArtemisMq created suxesfull.n");
}
catch (Exception ex)
{
Console.WriteLine($"Exception during the connecting to ArtemisMq: {ex.Message}n");
isConnected = false;
}
}
}
It is BrokerConfigSection in App.config file of my project:
<BrokerConfigSection
ArtemisMQConnectionString="tcp://0.0.0.0:61617"
ArtemisMQUserName="admin"
ArtemisMQPassword="admin"
ArtemisMQQueueName="ExpiryQueue">
</BrokerConfigSection>
It is an acceptor’s configuration in broker.xml file of Artemis:
<acceptor name="amqps-acceptor">tcp://0.0.0.0:61617?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=CORE,AMQP,STOMP,MQTT,OPENWIRE;useEpoll=true;sslEnabled=true;keyStoreAlias=amq1;keyStorePath=file:/certs/keystore.jks;keyStorePassword=11111111;enabledProtocols=TLSv1.2</acceptor>