Java Подключение Spring Boot к Artemis с включенным SSL - PullRequest
0 голосов
/ 03 февраля 2020

Я пытаюсь установить соединение между клиентом и Artemis с помощью SSL.

Я создал клиентские и брокерские хранилища ключей и трастовые хранилища. Таким образом, брокеры защищены с помощью SSL и могут общаться друг с другом, но с клиентом у меня проблема

@Bean
public ActiveMQConnectionFactory jmsFactory(@Value("${artemis.client.truststore}") String trustStorePath, @Value("${artemis.client.keystore}") String keyStorePath) {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
            "(tcp://192.168.2.101:61616,tcp://192.168.2.102:61616,tcp://192.168.2.103:61616)?ha=true" +
                    "sslEnabled=true&" +
                    "trustStorePath="+ trustStorePath + "&trustStorePassword=artemis&keyStorePath="+ keyStorePath +"&keyStorePassword=artemis");
    factory.setRetryInterval(1000);
    factory.setRetryIntervalMultiplier(1.0);
    factory.setReconnectAttempts(-1);
    factory.setConfirmationWindowSize(10);
    return factory;
}

application.properties

artemis.client.truststore=client_ts.p12
artemis.client.keytstore=client_ks.p12

, а вот мой брокер. xml:

<?xml version='1.0'?>

<configuration xmlns="urn:activemq"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xi="http://www.w3.org/2001/XInclude"
               xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">

   <core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="urn:activemq:core ">

      <name>0.0.0.0</name>

      <persistence-enabled>true</persistence-enabled>

      <journal-type>ASYNCIO</journal-type>

      <paging-directory>data/paging</paging-directory>

      <bindings-directory>data/bindings</bindings-directory>

      <journal-directory>data/journal</journal-directory>

      <large-messages-directory>data/large-messages</large-messages-directory>

      <journal-datasync>true</journal-datasync>

      <journal-min-files>2</journal-min-files>

      <journal-pool-files>10</journal-pool-files>

      <journal-device-block-size>4096</journal-device-block-size>

      <journal-file-size>10M</journal-file-size>

      <journal-buffer-timeout>28000</journal-buffer-timeout>

      <journal-max-io>4096</journal-max-io>

      <disk-scan-period>5000</disk-scan-period>

      <max-disk-usage>100</max-disk-usage>

      <critical-analyzer>true</critical-analyzer>

      <critical-analyzer-timeout>120000</critical-analyzer-timeout>

      <critical-analyzer-check-period>60000</critical-analyzer-check-period>

      <critical-analyzer-policy>HALT</critical-analyzer-policy>

      <page-sync-timeout>1628000</page-sync-timeout>

      <global-max-size>204Mb</global-max-size>

      <connectors>
         <connector name="netty-connector">tcp://amq1:61616?sslEnabled=true;keyStorePath=client_ks.p12;keyStorePassword=artemis;trustStorePath=client_ts.p12;trustStorePassword=artemis</connector>
      </connectors>
      <acceptors>
         <acceptor name="netty-acceptor">tcp://amq1:61616?sslEnabled=true;keyStorePath=broker_ks.p12;keyStorePassword=artemis;trustStorePath=broker_ts.p12;trustStorePassword=artemis;needClientAuth=true</acceptor>
      </acceptors>

      <cluster-connections>
         <cluster-connection name="my-cluster">
            <address>amq</address>
            <connector-ref>netty-connector</connector-ref>
            <retry-interval>1000</retry-interval>
            <retry-interval-multiplier>3</retry-interval-multiplier>
            <use-duplicate-detection>true</use-duplicate-detection>
            <message-load-balancing>STRICT</message-load-balancing>
            <discovery-group-ref discovery-group-name="my-discovery-group"/>
         </cluster-connection>
      </cluster-connections>

      <broadcast-groups>
         <broadcast-group name="my-broadcast-group">
            <local-bind-address>amq1</local-bind-address>
            <local-bind-port>9876</local-bind-port>
            <group-address>231.7.7.7</group-address>
            <group-port>9876</group-port>
            <broadcast-period>2000</broadcast-period>
            <connector-ref>netty-connector</connector-ref>
         </broadcast-group>
      </broadcast-groups>   

      <discovery-groups>
         <discovery-group name="my-discovery-group">
            <local-bind-address>amq1</local-bind-address>
            <local-bind-port>9876</local-bind-port>
             <group-address>231.7.7.7</group-address>
             <group-port>9876</group-port>
             <refresh-timeout>10000</refresh-timeout>
         </discovery-group>
      </discovery-groups>

      <network-check-list>amq1,amq2,amq3</network-check-list>   
      <network-check-period>5000</network-check-period>
      <network-check-timeout>1000</network-check-timeout>
      <network-check-ping-command>ping -c 1 -t %d %s</network-check-ping-command>
      <network-check-ping6-command>ping6 -c 1 %2$s</network-check-ping6-command>

      <!-- Other config -->
      <ha-policy>
        <replication>
          <master>
            <check-for-live-server>true</check-for-live-server>
          </master>
        </replication>
      </ha-policy>

      <security-settings>
         <security-setting match="#">
            <permission type="createNonDurableQueue" roles="amq"/>
            <permission type="deleteNonDurableQueue" roles="amq"/>
            <permission type="createDurableQueue" roles="amq"/>
            <permission type="deleteDurableQueue" roles="amq"/>
            <permission type="createAddress" roles="amq"/>
            <permission type="deleteAddress" roles="amq"/>
            <permission type="consume" roles="amq"/>
            <permission type="browse" roles="amq"/>
            <permission type="send" roles="amq"/>
            <!-- we need this otherwise ./artemis data imp wouldn't work -->
            <permission type="manage" roles="amq"/>
         </security-setting>
      </security-settings>

      <addresses>
         <address name="exampleQueue">
            <anycast>
               <queue name="exampleQueue"/>
            </anycast>
         </address>
         <address name="DLQ">
            <anycast>
               <queue name="DLQ" />
            </anycast>
         </address>
         <address name="ExpiryQueue">
            <anycast>
               <queue name="ExpiryQueue" />
            </anycast>
         </address>
      </addresses>

      <address-settings>
         <!-- if you define auto-create on certain queues, management has to be auto-create -->
         <address-setting match="activemq.management#">
            <dead-letter-address>DLQ</dead-letter-address>
            <expiry-address>ExpiryQueue</expiry-address>
            <redelivery-delay>0</redelivery-delay>
            <!-- with -1 only the global-max-size is in use for limiting -->
            <max-size-bytes>-1</max-size-bytes>
            <message-counter-history-day-limit>10</message-counter-history-day-limit>
            <address-full-policy>PAGE</address-full-policy>
            <auto-create-queues>true</auto-create-queues>
            <auto-create-addresses>true</auto-create-addresses>
            <auto-create-jms-queues>true</auto-create-jms-queues>
            <auto-create-jms-topics>true</auto-create-jms-topics>
         </address-setting>
         <!--default for catch all-->
         <address-setting match="#">
            <dead-letter-address>DLQ</dead-letter-address>
            <expiry-address>ExpiryQueue</expiry-address>
            <redelivery-delay>0</redelivery-delay>
            <!-- with -1 only the global-max-size is in use for limiting -->
            <max-size-bytes>-1</max-size-bytes>
            <message-counter-history-day-limit>10</message-counter-history-day-limit>
            <address-full-policy>PAGE</address-full-policy>
            <auto-create-queues>true</auto-create-queues>
            <auto-create-addresses>true</auto-create-addresses>
            <auto-create-jms-queues>true</auto-create-jms-queues>
            <auto-create-jms-topics>true</auto-create-jms-topics>
         </address-setting>
         <address-setting match="exampleQueue">            
            <dead-letter-address>DLQ</dead-letter-address>                      
            <redelivery-delay>1000</redelivery-delay>    
            <max-delivery-attempts>3</max-delivery-attempts>
            <max-size-bytes>-1</max-size-bytes>
            <page-size-bytes>1048576</page-size-bytes>
            <message-counter-history-day-limit>10</message-counter-history-day-limit>
            <address-full-policy>PAGE</address-full-policy>
        </address-setting>
      </address-settings>
   </core>
</configuration>

Когда я запускаю свой Java клиент, который отправляет сообщения в ActiveMQ Artemis, ничего не происходит, и через несколько секунд мой брокер выдает ошибку:

2020-02-03 15:50:18,091 ERROR [org.apache.activemq.artemis.core.server] AMQ224088: Timeout (10 seconds) on acceptor "netty-acceptor" during protocol handshake with /192.168.2.105:42942 has occurred.

Java клиент работает на 192.168.2.105.

1 Ответ

1 голос
/ 03 февраля 2020

Похоже, ваш код фабрики соединений содержит синтаксическую ошибку в URL. Вот код, который вы используете:

ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
            "(tcp://192.168.2.101:61616,tcp://192.168.2.102:61616,tcp://192.168.2.103:61616)?ha=true" +
                    "sslEnabled=true&" +
                    "trustStorePath="+ trustStorePath + "&trustStorePassword=artemis&keyStorePath="+ keyStorePath +"&keyStorePassword=artemis");

Это приведет к URL-адресу, подобному следующему:

(tcp://192.168.2.101:61616,tcp://192.168.2.102:61616,tcp://192.168.2.103:61616)?ha=truesslEnabled=true&trustStorePath=/some/path&trustStorePassword=artemis&keyStorePath=/some/other/path&keyStorePassword=artemis

Обратите внимание, что до sslEnabled=true нет разделителя &. Попробуйте вместо этого:

ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
            "(tcp://192.168.2.101:61616,tcp://192.168.2.102:61616,tcp://192.168.2.103:61616)?ha=true&" +
                    "sslEnabled=true&" +
                    "trustStorePath="+ trustStorePath + "&trustStorePassword=artemis&keyStorePath="+ keyStorePath +"&keyStorePassword=artemis");
...