Announcement Announcement Module
Collapse
No announcement yet.
problems trying to override the default username, password and virtual host Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problems trying to override the default username, password and virtual host

    Hi! All,

    I want to override the virutal host, user and password for the rabbit configuration. Here is the configuration used by me

    Code:
    	<beans:bean id="cachingConnectionFactory"
    		class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
    		<beans:constructor-arg value="localhost"/>
    		<beans:property name="virtualHost" value="analytics" />
    		<beans:property name="username" value="analytics" />
    		<beans:property name="password" value="analytics" />		
    		<beans:property name="channelCacheSize" value="5" />
    	</beans:bean>
    
    	<rabbit:queue id='analytics.persistence.queue' name='analytics.persistence.queue' />
    
    	<rabbit:direct-exchange name="amq.direct">
    		<rabbit:bindings>
    			<rabbit:binding queue="analytics.persistence.queue">
    			</rabbit:binding>
    		</rabbit:bindings>
    	</rabbit:direct-exchange>
    
    	<rabbit:connection-factory id="cachingConnectionFactory" />
    
    	<rabbit:admin connection-factory="cachingConnectionFactory" />
    
    	<beans:bean id="rabbitTemplate"
    		class="org.springframework.amqp.rabbit.core.RabbitTemplate">
    		<beans:property name="connectionFactory" ref="cachingConnectionFactory" />
    		<beans:property name="exchange" value="amq.direct" />
    		<beans:property name="queue" value="analytics.persistence.queue" />
    		<beans:property name="routingKey" value="save.analytics"></beans:property>
    	</beans:bean>
    
    	<beans:bean id="analyticsMessageProducer"
    		class="hoodibaba.analytics.publish.AnalyticsPersistenceMessageProducer"
    		autowire="byName" />
    
    
    	<context:component-scan base-package="hoodibaba.social.endpoint" />
    
    </beans:beans>

    However this does not work as I get authnetication errors / connection resets in logs (complete stack trace attached, here is an extract)
    Code:
    Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; reason: java.net.SocketException: Connection reset
    	at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
    	at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
    	at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)
    	at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:216)
    	at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)
    	... 47 more
    Caused by: java.net.SocketException: Connection reset
    	at java.net.SocketInputStream.read(SocketInputStream.java:189)
    	at java.net.SocketInputStream.read(SocketInputStream.java:121)
    	at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    	at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
    	at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288)
    	at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95)
    	at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:131)
    	at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:508)
    In rabbit logs I see

    Code:
    =INFO REPORT==== 19-Mar-2013::10:36:35 ===
    accepting AMQP connection <0.17407.0> (127.0.0.1:45191 -> 127.0.0.1:5672)
    
    =ERROR REPORT==== 19-Mar-2013::10:36:38 ===
    closing AMQP connection <0.17407.0> (127.0.0.1:45191 -> 127.0.0.1:5672):
    {handshake_error,opening,0,
                     {amqp_error,access_refused,
                                 "access to vhost '/' refused for user 'guest'",
                                 'connection.open'}}
    here are the rabbit permissions

    Code:
    [anadi@blramisr101575 hoodibaba]$ rabbitmqadmin --host=localhost --port=15672 -u admin -p admin list permissions
    +-----------+-----------+------+-----------+-------+
    |   vhost   | configure | read |   user    | write |
    +-----------+-----------+------+-----------+-------+
    | /         | .*        | .*   | admin     | .*    |
    | analytics | .*        | .*   | admin     | .*    |
    | analytics | .*        | .*   | analytics | .*    |
    | analytics | .*        | .*   | guest     | .*    |
    | engage    | .*        | .*   | admin     | .*    |
    | engage    |           | .*   | engage    | .*    |
    +-----------+-----------+------+-----------+-------+
    Am I going wrong some where in the configuration?

    I noticed going through the code that an alternate configuration would be to add

    Code:
    	<beans:bean id="rabbitConnectionFactory" class="com.rabbitmq.client.ConnectionFactory">
    		<beans:property name="virtualHost" value="analytics" />
    		<beans:property name="username" value="analytics" />
    		<beans:property name="password" value="analytics" />
    	</beans:bean>
    and then change caching connection factory to

    Code:
    	<beans:bean id="cachingConnectionFactory"
    		class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
    		<beans:constructor-arg type="com.rabbitmq.client.ConnectionFactory"
    			ref="rabbitConnectionFactory" />		
    		<beans:property name="channelCacheSize" value="5" />
    	</beans:bean>
    but also doesn't help and gives a possible authentication failure exception.

    For now I have reverted to using guest on default virtual host; but I want to know the solution for this because multiple virtual hosts are needed for different customers and each of them will be at times using the admin dashboard for viewing the changes.

  • #2
    I am using the wrong XML configuration, the caching connection factory is repeated as bean and using the rabbit name space, removed all declarations using beans namesscpace and it works now.

    Code:
    	<rabbit:queue id='analytics.persistence.queue' name='analytics.persistence.queue' />
    
    	<rabbit:direct-exchange name="amq.direct">
    		<rabbit:bindings>
    			<rabbit:binding queue="analytics.persistence.queue">
    			</rabbit:binding>
    		</rabbit:bindings>
    	</rabbit:direct-exchange>
    
    	<rabbit:connection-factory id="cachingConnectionFactory"
    		username="analytics" password="analytics" channel-cache-size="5"
    		virtual-host="analytics" />
    
    	<rabbit:admin connection-factory="cachingConnectionFactory" />
    
    	<beans:bean id="rabbitTemplate"
    		class="org.springframework.amqp.rabbit.core.RabbitTemplate">
    		<beans:property name="connectionFactory" ref="cachingConnectionFactory" />
    		<beans:property name="exchange" value="amq.direct" />
    		<beans:property name="queue" value="analytics.persistence.queue" />
    		<beans:property name="routingKey" value="save.analytics"></beans:property>
    	</beans:bean>
    
    	<beans:bean id="analyticsMessageProducer"
    		class="hoodibaba.analytics.publish.AnalyticsPersistenceMessageProducer"
    		autowire="byName" />

    Comment

    Working...
    X