使用Solj查询时,有时能获取到结果,有时获取不到结果,报SolrServerException server refused connection

josh_wang23 发布于 2015/11/26 09:30
阅读 1K+
收藏 0
1.使用的环境是Solr5.3.1和JDK1.7 

2.使用Solr自带的Jetty在远程的一台机器:192.168.1.155上启动Solr,其实我也试过使用Tomcat的方式来启动Solr,也有相同的问题。其中创建的core 的名字叫"universal" 

3. 下面是相关的Junit Test 
@Test 
   public void queryTest() throws SolrServerException, IOException { 
     SolrClient solrClient = new HttpSolrClient("http://192.168.1.155:8983/solr/universal"); 
     
     SolrParams params = new SolrQuery("id:7"); 
     QueryResponse response = solrClient.query(params); 
     System.out.println( " result ---- " + response); 
     solrClient.close(); 


4.有时候运行单元测试的时候是成功的: 
result ---- {responseHeader={status=0,QTime=0,params={q=id:7,wt=javabin,version=2}},response={numFound=1,start=0,docs=[SolrDocument{id=6, name=[HTC-TopOne], manu=HTC music。, popularity=[9], last_update_time=Fri Nov 06 11:23:23 CST 2015, _version_=1517177477028380672}]}} 


5. 有时候是失败的,如果失败了,但如果我接着多运行几次,就会成功,如果接着运行,就会一直成功,但是当我停一分钟再运行,单元测试又失败了,异常就是Socket Connection Exception,我调试过源码,确实是Socket异常。 

org.apache.solr.client.solrj.SolrServerException: Server refused connection at: http://192.168.1.155:8983/solr/universal 
at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:567) 
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:234) 
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:226) 
at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:135) 
at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:943) 
at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:958) 
at solr.TestSolrActionProxy.queryTest(TestSolrActionProxy.java:149) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 
Caused by: java.net.ConnectException: Connection timed out: connectx 
at java.net.DualStackPlainSocketImpl.connect0(Native Method) 
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) 
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) 
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) 
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) 
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) 
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) 
at java.net.Socket.connect(Socket.java:579) 
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446) 
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882) 
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) 
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) 
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) 
at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:465) 
... 30 more 


7. 所以我写了一段简单的代码来测试,发现确实在这种情况下,Socket有时会存在Connection异常,有时又是正常的。 


public static void main(String[] args)  { 
     Socket socket = new Socket(); 
     InetSocketAddress remoteAddress = new InetSocketAddress("192.168.1.155", 8983); 
     try { 
        socket.setKeepAlive(true); 
        socket.connect(remoteAddress, 5000); 
        System.out.println("----------------- end normallly"); 
     } catch (IOException e) { 
        e.printStackTrace(); 
     } 
     
     System.out.println(" ------------------- end "); 
   } 


大家有碰到过类似的问题没? 
加载中
0
颜朋
颜朋
问题解决了没有?怎么解决的?
0
Solr中国
Solr中国
需要catch Exception才能看到原因
0
s
satan_ljc

ip地址更换成机器名试试

我使用localhost报错,换成本机ip就好了

0
北方的狼族
楼主怎么解决的啊,遇到同样的问题
返回顶部
顶部