骆驼没有消耗SpringMQ消息弹簧启动

时间:2015-11-02 11:19:07

标签: spring spring-boot apache-camel activemq

我正在尝试配置Spring Boot,Apache Camel,ActiveMQ。这就是我到目前为止所做的:

  1. 我使用activemq.bat
  2. 运行ActiveMQ
  3. 我登录控制台监控消息
  4. 我开始后端服务(下面的来源)
  5. 我开始前端服务(Backend和Frontend是不同的春季启动项目)
  6. 我从前端发送消息到队列中,但是在20多秒后,我正在超时。该消息显示在ActiveMQ控制台中,但后端不会使用该消息。
  7. 以下是我配置后端的方法:

    的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 camel config

    <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
    

    公共接口和传输对象在第3个项目中定义,它是后端和前端项目的依赖项。

    我觉得这个配置中缺少一个部分。请告诉我它可能是什么。

    提前致谢。

1 个答案:

答案 0 :(得分:0)

您需要更改

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

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

或将您的端点网址更改为.to("activemq:queue:users")

ActiveMQComponent的id是.to()中用来标识要使用该组件定义的camel的名称。