.NET Framework 4.7.2客户端无法与ActiveMQ Artemis建立TLS1.2加密连接
问题概述
执行代码connection = await connectionFactory.CreateAsync(endpoints);时返回null,无任何异常抛出,ActiveMQ Artemis端也未记录连接尝试的错误日志。
需求背景:需要与Docker容器中运行的ActiveMQ Artemis建立TLS 1.2加密连接,所有证书仅部署在ActiveMQ Artemis端。项目基于.NET Framework 4.7.2,将在Linux的Mono环境运行(Mono不支持X509证书),因此.NET客户端不能持有证书。
当前状态:使用同款.NET库通过普通TCP发送消息至该ActiveMQ Artemis可正常工作,使用的库为“.NET Client for Apache ActiveMQ Artemis”。
客户端核心代码
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..."); 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."); } catch (Exception ex) { Console.WriteLine($"Exception during the connecting to ArtemisMq: {ex.Message}"); isConnected = false; } } }
项目App.config配置
<BrokerConfigSection ArtemisMQConnectionString="tcp://0.0.0.0:61617" ArtemisMQUserName="admin" ArtemisMQPassword="admin" ArtemisMQQueueName="ExpiryQueue"> </BrokerConfigSection>
ActiveMQ Artemis broker.xml acceptor配置
<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>
内容的提问来源于stack exchange,提问作者Raman Shuliak
相关产品推荐
相关产品推荐

