当我尝试发送消息时,出现以下异常。该 URL 似乎正确,我之前使用过类似的配置。我不知道什么可能导致这个问题......
Caused by: javax.naming.NamingException: invalid URL: protocol != smqp, URL==smqp://activemq:3001/timeout=10000
at com.swiftmq.jndi.v400.URLParser.parseURL(Unknown Source)
at com.swiftmq.jndi.InitialContextFactoryImpl.getInitialContext(Unknown Source)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at org.springframework.jndi.JndiTemplate.createInitialContext(JndiTemplate.java:136)
at org.springframework.jndi.JndiTemplate.getContext(JndiTemplate.java:103)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:127)
... 50 more
配置
<!-- JMS Connection Factory -->
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.provider.url">smqp://activemq:3001/timeout=10000</prop>
<prop key="java.naming.factory.initial">com.swiftmq.jndi.InitialContextFactoryImpl</prop>
</props>
</property>
</bean>
<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="jndiName" value="QueueConnectionFactory" />
<property name="lookupOnStartup" value="false" />
<property name="cache" value="false" />
<property name="proxyInterface" value="javax.jms.QueueConnectionFactory" />
</bean>
<bean id="sendConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory" destroy-method="destroy">
<property name="targetConnectionFactory" ref="jmsConnectionFactory" />
<property name="reconnectOnException" value="true" />
<property name="sessionCacheSize" value="100"/>
</bean>
<!-- Template used only for sending messages -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="sendConnectionFactory" />
<property name="defaultDestinationName" value="request@z4smq_4001" />
</bean>
用法
MessageCreator messageCreator = new MessageCreatorImpl(payload);
jmsTemplate.send(messageCreator); // setter injection