Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache camel 制造商和制造商的连接工厂;消费者_Apache Camel - Fatal编程技术网

Apache camel 制造商和制造商的连接工厂;消费者

Apache camel 制造商和制造商的连接工厂;消费者,apache-camel,Apache Camel,我用骆驼。请让我知道以下方法是否合适 生产者共因失效 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring" xm

我用骆驼。请让我知道以下方法是否合适

生产者共因失效

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="hornetConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
        <constructor-arg name="ha" value="false"></constructor-arg>
        <constructor-arg>
            <bean id="transportConfiguration" class="org.hornetq.api.core.TransportConfiguration">
                <constructor-arg
                    value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
                <constructor-arg>
                    <map key-type="java.lang.String" value-type="java.lang.Object">
                        <entry key="host" value="127.0.0.1" />
                        <entry key="port" value="5445" />
                    </map>
                </constructor-arg>
            </bean>
        </constructor-arg>
    </bean>

    <!-- ConnectionFactory Definition -->
    <bean id="connectionFactory"
        class="org.springframework.jms.connection.CachingConnectionFactory">
        <constructor-arg ref="hornetConnectionFactory" />
    </bean>

    <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="connectionFactory" />
    </bean>

    <context:component-scan base-package="com.camlin.producer" />

    <camel:camelContext id="camel-server">
        <camel:package>com.camlin.producer</camel:package>
    </camel:camelContext>
</beans>

com.camlin.producer
消费者的正常CF

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="hornetConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
        <constructor-arg name="ha" value="false"></constructor-arg>
        <constructor-arg>
            <bean id="transportConfiguration" class="org.hornetq.api.core.TransportConfiguration">
                <constructor-arg
                    value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
                <constructor-arg>
                    <map key-type="java.lang.String" value-type="java.lang.Object">
                        <entry key="host" value="127.0.0.1" />
                        <entry key="port" value="5445" />
                    </map>
                </constructor-arg>
            </bean>
        </constructor-arg>
    </bean>

    <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="hornetConnectionFactory" />
    </bean>

    <context:component-scan base-package="com.camlin.consumer" />

    <camel:camelContext id="camel-consumer">
        <camel:package>com.camlin.consumer</camel:package>

        <camel:route id="one">
            <camel:from uri="jms:queue:request?selector=type='1'" />
            <camel:to uri="bean:consumerBean?method=receive1" />
        </camel:route>

        <camel:route id="two">
            <camel:from uri="jms:queue:request?selector=type='2'" />
            <camel:to uri="bean:consumerBean?method=receive2" />
        </camel:route>
    </camel:camelContext>
</beans>

com.camlin.consumer

对于生产者,您应该使用JMS连接池…通常是AMQ的PooledConnectionFactory或Spring的CachingConnectionFactory

对于使用者,应该尽可能使用Spring的over JmsTemplate.receive()

请参阅JmsTemplate最佳实践:


有关更多详细信息,请参阅本文:

如何在Camel中进行配置?如问题中所述,这是在Camel中配置消费者的正确方法吗?无论我在哪里看到ActiveMQ示例,JMSComponent都会将代理URL作为ctor arg获取。如何配置ConnectionFactory?因为我使用HornetQ作为JMS提供者