If you must use MuleClient, then you can try this:
public void sendMessage(Object msg){
Map props = new HashMap();
props.put("Sender", "Mule Client");
MuleClient muleClient = new MuleClient();
muleClient.dispatch("jms://localhost:61616/topic:manu.topic", msg, props);
}
The only problem with this is that your Java class needs to have the information about Active MQ, topic name, etc.
But if you want to send a message through Mule but don't have to use MuleClient, I would recommend this approach to remove all transport specific information from your Java client:
Add this to your mule config:
<jms:activemq-connector name="JMSConnector" connectionFactory-ref="activeMqConnectionFactory">
<spring:beans>
<spring:bean name="activeMqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<spring:property name="brokerURL" value="tcp://localhost:61616"/>
</spring:bean>
</spring:beans>
</jms:activemq-connector>
<service name="TopicService">
<outbound>
<outbound-pass-through-router>
<jms:outbound-endpoint queue="topic:manu.topic" transformer-refs="ObjectToJMSTransformer" />
</outbound-pass-through-router>
</outbound>
</service>
And in your Java class, you can send your message using the service name "TopicService":
Service service = MuleServer.getMuleContext().getRegistry().lookupService("TopicService");
Manupriya wrote:
Hi,
My requirement is to have a standalone java class that just generates messages and puts them to an Active MQ Topic. I want to write something similar to following -
try {
MuleClient client = new MuleClient();
RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:61616");
for (String rowValue : rowList) {
dispatcher.sendAsyncRemote("jms://topic:manu.topic", rowValue, null);
}
} catch (MuleException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Can you please help?
Thanks,
Manupriya