Skip to content

Message Publish Subscribe

regunathb edited this page Nov 2, 2012 · 14 revisions

The Trooper RabbitMQ library provides a convenient way to perform simple publish-subscribe operations. The publisher interface offers these useful methods:

public void publish(Object message) throws MessagingException;
public void publishString(String message) throws MessagingException;

The consumer interface provides these methods:

public Object consume() throws MessagingException;
public String consumeString() throws MessagingException;

Common methods for both these interfaces are:

public int getQueueDepth() throws MessagingException;
public void closeConnections() throws MessagingException;

The Spring XML beans to create and use the Publisher may be defined as:

	<bean id="greetingMessagePublisher" class="org.trpr.platform.integration.impl.messaging.RabbitMQMessagePublisherImpl">
		<property name="rabbitMQConfigurations">
			<list>
				<ref bean="greetingQueueConfiguration" />
			</list>
		</property>
	</bean>		
	<bean id="greetingQueueConfiguration" class="org.trpr.platform.integration.impl.messaging.RabbitMQConfiguration">
        <property name="userName" value="guest" />
        <property name="password" value="guest" />
        <property name="hostName" value="localhost" />
        <property name="virtualHost" value="/" />
        <property name="exchangeName" value="myexchange" />
		<property name="queueName" value="greetingInput" />
		<property name="exchangeType" value="direct" />
		<property name="routingKey" value="greetingInput" />
        <property name="portNumber" value="5672" />
	</bean>