2015-11-02 59 views
0

我正在嘗試配置Spring Boot,Apache Camel,ActiveMQ所有接收器。這是我做過什麼至今:ActiveMQ消息不消耗彈簧引導,駱駝

  1. 我使用activemq.bat
  2. 我登錄到控制檯來監控信息運行的ActiveMQ
  3. 我開始後端服務(以下來源)
  4. 我啓動前端服務(後端和前端是不同的彈簧引導項目)
  5. 我從前端向隊列發送消息,但在20秒後我得到超時。該消息出現在ActiveMQ控制檯中,但不會被後端使用。

我是這樣配置的後端:

的build.gradle:

dependencies { 
    compile("org.apache.camel:camel-spring-boot:2.16.0") 
    compile("org.springframework.boot:spring-boot-starter-web") 
    compile("org.springframework.boot:spring-boot-starter-websocket") 
    compile("org.springframework:spring-messaging") 
    compile("org.springframework:spring-jms") 
    compile("org.springframework.security:spring-security-web") 
    compile("org.springframework.security:spring-security-config") 
    compile("org.springframework.boot:spring-boot-starter-data-jpa") 
    compile('org.apache.camel:camel-jms:2.16.0') 
    compile("org.hibernate:hibernate-core:4.0.1.Final") 
    compile("mysql:mysql-connector-java:5.1.37") 
    compile("log4j:log4j:1.2.16") 
    compile("junit:junit:4.12") 
    compile("org.mockito:mockito-all:1.8.4") 
    compile('org.apache.activemq:activemq-core:5.7.0') 
    compile('com.epam.training.auction:auction_common:1.0') 
    testCompile("junit:junit") 
} 

路由配置:(我用UsersServiceImpl用於測試和確定它的兩種方式不工作)

import org.apache.camel.RoutesBuilder; 
import org.apache.camel.builder.RouteBuilder; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 

import com.epam.training.auction_backend.services.UsersServiceImpl; 

@Configuration 
public class MyRouterConfiguration { 
    @Bean 
    public RoutesBuilder myRouter() { 
    return new RouteBuilder() { 

     @Override 
     public void configure() throws Exception { 
      from("jms:queue:auctions").to("bean:auctionsServiceImpl"); 
      from("jms:queue:users").bean(UsersServiceImpl.class); 
      from("jms:queue:bidding").to("bean:biddingServiceImpl"); 
     } 
    }; 
    } 
} 

客戶端,調用方法

@Override 
public void registerUser(String username, String password) { 
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client-remoting.xml"); 
    UsersService usersService = context.getBean("usersServiceImpl", UsersService.class); 

    System.out.println("Invoking the logging"); 
    UserTransferObject userTransferObject = new UserTransferObject("user", "pass"); 
    usersService.addUser(userTransferObject); 
    System.out.println("User is logged"); 

    IOHelper.close(context); 
} 

客戶端的XML駱駝配置

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:camel="http://camel.apache.org/schema/spring" 
     xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> 

    <camel:camelContext id="camel-client"> 
    <camel:template id="camelTemplate"/> 

    <camel:proxy 
     id="auctionsServiceImpl" 
     serviceInterface="com.epam.training.auction.common.AuctionsService" 
     serviceUrl="jms:queue:auctions"/> 

    <camel:proxy 
     id="usersServiceImpl" 
     serviceInterface="com.epam.training.auction.common.UsersService" 
     serviceUrl="jms:queue:users"/> 

    <camel:proxy 
     id="biddingServiceImpl" 
     serviceInterface="com.epam.training.auction.common.BiddingService" 
     serviceUrl="jms:queue:bidding"/> 
    </camel:camelContext> 

    <bean id="jmsConnectionFactory" 
     class="org.apache.activemq.ActiveMQConnectionFactory"> 
    <property name="brokerURL" value="tcp://localhost:61616"/> 
    </bean> 

    <bean id="pooledConnectionFactory" 
     class="org.apache.activemq.pool.PooledConnectionFactory" 
     init-method="start" destroy-method="stop"> 
    <property name="maxConnections" value="8"/> 
    <property name="connectionFactory" ref="jmsConnectionFactory"/> 
    </bean> 

    <bean id="jmsConfig" 
     class="org.apache.camel.component.jms.JmsConfiguration"> 
    <property name="connectionFactory" ref="pooledConnectionFactory"/> 
    <property name="concurrentConsumers" value="10"/> 
    </bean> 

    <bean id="jms" 
     class="org.apache.activemq.camel.component.ActiveMQComponent"> 
    <property name="configuration" ref="jmsConfig"/> 
    <property name="transacted" value="true"/> 
    <property name="cacheLevelName" value="CACHE_CONSUMER"/> 
    </bean> 

</beans> 

在送我也得到警告:

2015-11-02 11:56:21.547 WARN 16328 --- [nio-8181-exec-5] o.s.b.f.s.DefaultListableBeanFactory  : Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usersServiceImpl': Invocation of init method failed; nested exception is org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jms://queue:users due to: Cannot auto create component: jms 

常用接口NAD轉移對象在3定義該項目是後端和前端項目的依賴項目。

我覺得這個配置有一個缺失部分。請告訴我它可能是什麼。

在此先感謝。

回答

0

您需要更改

<bean id="activemq" 
    class="org.apache.activemq.camel.component.ActiveMQComponent"> 

<bean id="jms" 
    class="org.apache.activemq.camel.component.ActiveMQComponent"> 

或更改端點的URL .to("activemq:queue:users")

您的ActiveMQComponent的id是在.to()中使用的名稱,以標識駱駝您想要使用該組件定義。

+0

謝謝你的答案。不幸的是它沒有幫助。我在服務器端收到了「可能的模糊方法調用」,但我無法重現。可能它不是一步之遙,只是沒有連接錯誤。後端方面沒有做任何事情,消息被張貼和超時。 –

+0

您是否可以更新您的原始問題,以便更改您剛剛更改的內容,以便我可以查看是否有某些我錯過的內容? – fiw

+0

我更新了它。 activemq id已更改爲jms –