しばらくの間、cloudfoundry.com で実行しているアプリケーションがあり、api.cloudfoundry.com にデプロイするとすべてがうまく機能します。最近、クラウド環境でローカル テストを行うために CF マイクロ インスタンスをセットアップしましたが、アプリケーションをマイクロ インスタンスにデプロイすると、ウサギ サービスに接続できません。次の例外が発生します。
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.integration.MessageHandlingException: error occurred in message handler [org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint#0]
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
...
org.springframework.integration.MessageHandlingException: error occurred in message handler [org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint#0]
org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:79)
org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115)
org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:102)
...
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection timed out
org.springframework.amqp.rabbit.connection.RabbitUtils.convertRabbitAccessException(RabbitUtils.java:109)
org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:163)
org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:228)
org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:119)
org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:163)
org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:109)
org.springframework.amqp.rabbit.connection.RabbitAccessor.getTransactionalResourceHolder(RabbitAccessor.java:100)
org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:591)
org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:329)
org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:385)
org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint.send(AmqpOutboundEndpoint.java:200)
org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint.handleRequestMessage(AmqpOutboundEndpoint.java:192)
何を見ればいいのかわからない (マイクロ インスタンスに何か確認できるものがあると確信しているが、何を確認できるかはわからない) ので、ここで質問したいと思いました。
サービスが存在することを確認しました:
vmc services
Getting services... OK
name service version
xxx-mongo mongodb 2.0
xxx-mysql mysql 5.1
xxx-rabbit rabbitmq 2.4
サービスがアプリケーションにバインドされていることを確認しました。
vmc app myapp
myapp: running
platform: spring on java
usage: 512M × 1 instance
urls: mydomain.cloudfoundry.me
services: xxx-mysql, xxx-rabbit, xxx-mongo
私もそれを再バインドしようとしましたが、それはバインドされていると言います:
vmc bind-service xxx-rabbit myapp
Binding xxx-rabbit to myapp... SKIPPED
App myapp already binds xxx-rabbit.
私のアプリは Spring アプリケーションです。rabbit サービスの構成は次のように設定されます。
<?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:cloud="http://schema.cloudfoundry.org/spring"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.1.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://schema.cloudfoundry.org/spring
http://schema.cloudfoundry.org/spring/cloudfoundry-spring.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<!-- MongoDB setup -->
<mongo:db-factory
id="mongoDbFactory"
dbname="xxx"
host="127.0.0.1"
port="27017"
username="test_user"
password="test_pass" />
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory" />
</bean>
<!-- Set up the AmqpTemplate/RabbitTemplate: -->
<rabbit:connection-factory id="rabbitConnectionFactory"/>
<rabbit:template id="rabbitTemplate" connection-factory="rabbitConnectionFactory"/>
<bean id="jdbcDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://127.0.0.1:3306/test" />
<property name="username" value="spring" />
<property name="password" value="spring" />
</bean>
<jdbc:initialize-database data-source="jdbcDataSource">
<jdbc:script location="classpath:oauthTokenStoreSchema.sql"/>
</jdbc:initialize-database>
</beans>
この構成は、Spring の自動再構成に依存しており、私が知る限り正常に機能しています。次のように実際にメッセージをキューに送信しようとした場合にのみ、スタートアップとして文句を言いません。
org.springframework.integration.Message<Message> msg = MessageBuilder.withPayload(m).build();
messagesChannel.send(msg);
最後に、マイクロ インスタンスにログインして、rabbit が実際に実行されているかどうかを確認しました。
vcap@micro:~$ ps -ef | grep rabbit
root 1492 1 0 Jan14 ? 00:17:00 ruby /var/vcap/packages/rabbit_node/services/rabbit/bin/rabbit_node -c /var/vcap/jobs/rabbit_node/config/rabbit_node.yml
root 1509 1 0 Jan14 ? 00:14:48 ruby /var/vcap/packages/rabbit_gateway/services/ng/rabbit/bin/rabbit_gateway -c /var/vcap/jobs/rabbit_gateway/config/rabbit_gateway.yml
root 1771 1492 0 Jan14 ? 00:14:36 /var/vcap/data/packages/erlang/3/lib/erlang/erts-5.8.2/bin/beam -W w -K true -A30 -P 1048576 -- -root /var/vcap/data/packages/erlang/3/lib/erlang -progname erl -- -home /var/vcap/store/rabbit/instances/d55204b5-814c-4c64-bd35-861d77ee927d -- -noshell -noinput -sname d55204b5-814c-4c64-bd35-861d77ee927d@localhost -boot /var/vcap/store/rabbit/instances/d55204b5-814c-4c64-bd35-861d77ee927d/plugins/rabbit -config /var/vcap/store/rabbit/instances/d55204b5-814c-4c64-bd35-861d77ee927d/config/rabbitmq -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{"10.0.1.21",10001}] -sasl errlog_type error -kernel error_logger {file,"/var/vcap/sys/service-log/rabbit/d55204b5-814c-4c64-bd35-861d77ee927d/d55204b5-814c-4c64-bd35-861d77ee927d@localhost.log"} -sasl sasl_error_logger {file,"/var/vcap/sys/service-log/rabbit/d55204b5-814c-4c64-bd35-861d77ee927d/d55204b5-814c-4c64-bd35-861d77ee927d@localhost-sasl.log"} -os_mon start_cpu_sup true -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/var/vcap/store/rabbit/instances/d55204b5-814c-4c64-bd35-861d77ee927d/mnesia" -smp disable
vcap 49299 49278 0 02:38 pts/0 00:00:00 grep --color=auto rabbit
ここでも、api.cloudfoundry.com にデプロイすると、アプリは rabbitmq に問題なく接続できます。それが役立つ場合は、マイクロのv119も実行しています。
あなたが提供できるどんな助けも素晴らしいでしょう!ありがとう。
編集:Hitesh の推奨に従って、クラウド プロファイルを使用しようとしましたが、うまくいきませんでした。私もこれを試しました:
<beans profile="default">
<rabbit:connection-factory
id="rabbitConnectionFactory"
host="localhost"
password="testpwd"
port="1238"
username="testuser"
virtual-host="virthost" />
<rabbit:template id="rabbitTemplate" connection-factory="rabbitConnectionFactory"/>
</beans>
<beans profile="cloud">
<cloud:rabbit-connection-factory id="rabbitConnectionFactory" />
<rabbit:template id="rabbitTemplate" connection-factory="rabbitConnectionFactory"/>
</beans>
興味深いのは、私がこれを試したことです(ドキュメントからコピーされました):
<rabbit:connection-factory
id="rabbitConnectionFactory"
host="localhost"
password="testpwd"
port="1238"
username="testuser"
virtual-host="virthost" />
<rabbit:template id="rabbitTemplate" connection-factory="rabbitConnectionFactory"/>
そして今、私の送信アプリケーションが動作します! しかし、私の受信アプリはまだ動作しません。次のエラーが発生します。
ERROR: main org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter#0'; nested exception is org.springframework.amqp.UncategorizedAmqpException: java.util.concurrent.TimeoutException: Timed out waiting for startup
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:170)
at org.springframework.context.support.DefaultLifecycleProcessor.access$1(DefaultLifecycleProcessor.java:154)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:339)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:143)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:108)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:926)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.amqp.UncategorizedAmqpException: java.util.concurrent.TimeoutException: Timed out waiting for startup
at org.springframework.amqp.rabbit.connection.RabbitUtils.convertRabbitAccessException(RabbitUtils.java:118)
at org.springframework.amqp.rabbit.connection.RabbitAccessor.convertRabbitAccessException(RabbitAccessor.java:106)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.start(AbstractMessageListenerContainer.java:365)
at org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter.doStart(AmqpInboundChannelAdapter.java:85)
at org.springframework.integration.endpoint.AbstractEndpoint.start(AbstractEndpoint.java:84)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:167)
... 39 more
Caused by: java.util.concurrent.TimeoutException: Timed out waiting for startup
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.getStartupException(SimpleMessageListenerContainer.java:512)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doStart(SimpleMessageListenerContainer.java:337)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.start(AbstractMessageListenerContainer.java:363)
... 42 more
上記のすべての構成を試しましたが、どれも機能しません。