2016-03-10 105 views
1

在下面複製客戶端和服務器配置爲hazelcast v3.6。我可以運行服務器(監聽127.0.0.1:5706)在hazelcast客戶端和hazelcast服務器之間沒有建立連接

I get the following error on the hazelcast client side: 
[warn] c.h.c.c.n.ClientConnection - Connection [/127.0.0.1:5701] lost. Reason: java.lang.NullPointerException[null] 
[warn] c.h.c.s.i.ClusterListenerSupport - Unable to get alive cluster connection, try in 2986 ms later, attempt 1 of 2. 

hazelcast-client.xml的

<?xml version="1.0" encoding="UTF-8"?> 

    <hazelcast-client xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-3.6.xsd" 
        xmlns="http://www.hazelcast.com/schema/client-config" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

    <group> 
     <name>dev</name> 
     <password>dev-pass</password> 
    </group> 

    <properties> 
     <property name="hazelcast.client.shuffle.member.list">true</property> 
     <property name="hazelcast.client.heartbeat.timeout">60000</property> 
     <property name="hazelcast.client.heartbeat.interval">5000</property> 
     <property name="hazelcast.client.event.thread.count">5</property> 
     <property name="hazelcast.client.event.queue.capacity">1000000</property> 
     <property name="hazelcast.client.invocation.timeout.seconds">120</property> 
    </properties> 

    <network> 
     <cluster-members> 
      <address>127.0.0.1:5701</address> 
      <!-- <address>0.0.0.0</address> --> 
     </cluster-members> 
     <smart-routing>true</smart-routing> 
     <redo-operation>true</redo-operation> 
     <connection-timeout>60000</connection-timeout> 
     <connection-attempt-period>3000</connection-attempt-period> 
     <connection-attempt-limit>2</connection-attempt-limit> 
     <socket-options> 
      <tcp-no-delay>false</tcp-no-delay> 
      <keep-alive>true</keep-alive> 
      <reuse-address>true</reuse-address> 
      <linger-seconds>3</linger-seconds> 
      <timeout>-1</timeout> 
      <buffer-size>32</buffer-size> 
     </socket-options> 

     <socket-interceptor enabled="false"> 
      <class-name>com.hazelcast.examples.MySocketInterceptor</class-name> 
      <properties> 
       <property name="foo">bar</property> 
      </properties> 
     </socket-interceptor> 

     <ssl enabled="false"> 
      <factory-class-name>com.hazelcast.examples.MySslFactory</factory-class-name> 
     </ssl> 

     <aws enabled="false" connection-timeout-seconds="11"> 
      <inside-aws>true</inside-aws> 
      <access-key>TEST_ACCESS_KEY</access-key> 
      <secret-key>TEST_SECRET_KEY</secret-key> 
      <region>us-east-1</region> 
      <host-header>ec2.amazonaws.com</host-header> 
      <security-group-name>hazelcast-sg</security-group-name> 
      <tag-key>type</tag-key> 
      <tag-value>hz-nodes</tag-value> 
     </aws> 

    </network> 

    <executor-pool-size>40</executor-pool-size> <!-- reduce the pool size after profiling --> 


    <security> 
     <credentials>com.hazelcast.security.UsernamePasswordCredentials</credentials> 
    </security> 

    <listeners> 
     <!--<listener>com.hazelcast.examples.MembershipListener</listener> 
     <listener>com.hazelcast.examples.InstanceListener</listener> 
     <listener>com.hazelcast.examples.MigrationListener</listener> 
     --> 
    </listeners> 

    <!-- change to kryo --> 
<!-- <serialization> 
     <portable-version>3</portable-version> 
     <use-native-byte-order>true</use-native-byte-order> 
     <byte-order>BIG_ENDIAN</byte-order> 
     <enable-compression>false</enable-compression> 
     <enable-shared-object>true</enable-shared-object> 
     <allow-unsafe>false</allow-unsafe> 
     <data-serializable-factories> 
      <data-serializable-factory factory-id="1">com.hazelcast.examples.DataSerializableFactory 
      </data-serializable-factory> 
     </data-serializable-factories> 
     <portable-factories> 
      <portable-factory factory-id="2">com.hazelcast.examples.PortableFactory</portable-factory> 
     </portable-factories> 
     <serializers> 
      <global-serializer>com.hazelcast.examples.GlobalSerializerFactory</global-serializer> 
      <serializer type-class="com.hazelcast.examples.DummyType" 
         class-name="com.hazelcast.examples.SerializerFactory"/> 
     </serializers> 
     <check-class-def-errors>true</check-class-def-errors> 
    </serialization> 

--> 


    <native-memory enabled="false" allocator-type="POOLED"> 
     <size unit="MEGABYTES" value="128" /> 
     <min-block-size>1</min-block-size> 
     <page-size>1</page-size> 
     <metadata-space-percentage>40.5</metadata-space-percentage> 
    </native-memory> 

    <!-- 
    <proxy-factories> 
     <proxy-factory class-name="com.hazelcast.examples.ProxyXYZ1" service="sampleService1"/> 
     <proxy-factory class-name="com.hazelcast.examples.ProxyXYZ2" service="sampleService1"/> 
     <proxy-factory class-name="com.hazelcast.examples.ProxyXYZ3" service="sampleService3"/> 
    </proxy-factories> 
--> 
    <load-balancer type="random"/> 

    <!-- 
     Beware that near-cache eviction configuration is different for NATIVE in-memory format. 
     Proper eviction configuration example for NATIVE in-memory format : 
      `<eviction max-size-policy="USED_NATIVE_MEMORY_SIZE" eviction-policy="LFU" size="60"/>` 
    --> 

<!-- <near-cache name="default"> 
     <max-size>2000</max-size> 
     <time-to-live-seconds>90</time-to-live-seconds> 
     <max-idle-seconds>100</max-idle-seconds> 
     <eviction-policy>LFU</eviction-policy> 
     <invalidate-on-change>true</invalidate-on-change> 
     <in-memory-format>OBJECT</in-memory-format> 
     <local-update-policy>INVALIDATE</local-update-policy> 
    </near-cache> 
--> 
    <!-- 
    <query-caches> 
     <query-cache name="query-cache-name" mapName="map-name"> 
      <predicate type="class-name">com.hazelcast.examples.ExamplePredicate</predicate> 
      <entry-listeners> 
       <entry-listener include-value="true" local="false">com.hazelcast.examples.EntryListener</entry-listener> 
      </entry-listeners> 
      <include-value>true</include-value> 
      <batch-size>1</batch-size> 
      <buffer-size>16</buffer-size> 
      <delay-seconds>0</delay-seconds> 
      <in-memory-format>BINARY</in-memory-format> 
      <coalesce>false</coalesce> 
      <populate>true</populate> 
      <eviction eviction-policy="LRU" max-size-policy="ENTRY_COUNT" size="10000"/> 
      <indexes> 
       <index ordered="false">name</index> 
      </indexes> 
     </query-cache> 
    </query-caches> 
--> 

</hazelcast-client> 

hazelcast服務器

這裏是在控制檯消息服務器和服務器配置文件:

控制檯消息Ë

INFO: [127.0.0.1]:5701 [dev] [3.6] Established socket connection between /127.0.1.1:5701 and /127.0.0.1:47301 
Mar 10, 2016 12:01:48 PM com.hazelcast.nio.tcp.TcpIpConnection 
INFO: [127.0.0.1]:5701 [dev] [3.6] Connection [/127.0.0.1:47301] lost. Reason: java.io.EOFException[Remote socket closed!] 

hazelcast.xml(服務器)

<?xml version="1.0" encoding="UTF-8"?> 
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.6.xsd" 
      xmlns="http://www.hazelcast.com/schema/config" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <group> 
     <name>dev</name> 
     <password>dev-pass</password> 
    </group> 

    <network> 
     <port auto-increment="true" port-count="100">5701</port> 
     <outbound-ports> 
      <ports>0-5900</ports> 
     </outbound-ports> 
     <join> 
      <multicast enabled="false"> 
       <!--<multicast-group>224.2.2.3</multicast-group> 
       <multicast-port>54327</multicast-port>--> 
      </multicast> 
      <tcp-ip enabled="true"> 
       <member>127.0.0.1</member> 
      </tcp-ip> 
     </join> 
     <interfaces enabled="true"> 
      <interface>127.0.0.1</interface> 
     </interfaces> 
     <ssl enabled="false" /> 
     <socket-interceptor enabled="false" /> 
     <symmetric-encryption enabled="false"> 
      <algorithm>PBEWithMD5AndDES</algorithm> 
      <!-- salt value to use when generating the secret key --> 
      <salt>thesalt</salt> 
      <!-- pass phrase to use when generating the secret key --> 
      <password>thepass</password> 
      <!-- iteration count to use when generating the secret key --> 
      <iteration-count>19</iteration-count> 
     </symmetric-encryption> 
    </network> 

    <partition-group enabled="false"/> 

    <executor-service name="default"> 
     <pool-size>16</pool-size> 
     <!--Queue capacity. 0 means Integer.MAX_VALUE.--> 
     <queue-capacity>0</queue-capacity> 
    </executor-service> 

    <map name="userMap"> 
     <async-backup-count>1</async-backup-count> 

     <near-cache> 
      <max-size>5000</max-size> 
      <invalidate-on-change>true</invalidate-on-change> 
     </near-cache> 

     <map-store enabled="false"> 
      <class-name></class-name> 
      <write-delay-seconds>0</write-delay-seconds> 
     </map-store> 
    </map> 

</hazelcast> 

客戶端代碼

ClientConfig clientConfig = new XmlClientConfigBuilder().build(); //the xml file is being loaded 
HazelcastInstance hazelcastClient = HazelcastClient.newHazelcastClient(clientConfig); 

我沒有在我的電腦上運行的防火牆。對我可能錯誤配置的任何想法?

更新: 我能在我指定的程序,所以我假設的問題是IP地址連接或者與我的客戶端配置或如何我readig它:

ClientCOnfig clientConfig = new ClientConfig(); 
    clientConfig.getNetworkConfig().addAddress("127.0.0.1"); 
    HazelcastInstance hcastClient = HazelcastClient.newHazelcastClient(clientConfig); 

回答

2

問題是由客戶端配置xml文件中的以下行引起:

<security> 
<credentials>com.hazelcast.security.UsernamePasswordCredentials</credentials> 
</security> 

一旦這個被註釋掉了,客戶端就可以連接到服務器。一旦我收集有關其使用情況的更多信息,我將會更新。

似乎只能在企業版中使用,而不是社區中的一種,但理想情況下,它應該讓連接建立或生成有意義的錯誤消息。

相關問題