Mule How to use amqp connector global element object into Java file

In so many articles, you can find how to create amqp connector in mule configuration xml file, here is a good example for it.



Once you created the global element of amqp connector using below configuration:

<amqp:connector validateConnections="true" doc:name="AMQP Connector"  name="AMQP_0_9_Connector" />

Now you need to create a Java file where you want to inject this amqp connector. So create a java class like below:

public class RabbitMQ {
private AmqpConnector amqps;

public AmqpConnector getAmqps() {
return amqps;
}

public void setAmqps(AmqpConnector amqps) {
// MuleServer.
this.amqps = amqps;
}
}

Now come back in the mule configuration xml file and create bean global element here:

<spring:beans>
     <spring:bean id="rabbitMQ" name="rabbitMQ" class="com.hcl.muleMKT.RabbitMQ">
<spring:property name="amqps" ref="AMQP_0_9_Connector"></spring:property>
     </spring:bean>
</spring:beans>

Again you need to write below @Autowired method, in your BL java class where you want to use this connector object.

@Autowired
public RabbitMQ rabbitMQ;

public void anyMethod(RabbitMQ rabbitMQ) {
this.rabbitMQ = rabbitMQ;
}

public RabbitMQ getObj() {
return this.rabbitMQ;
}

Comments

  1. Nice example, I used some piece of code from here, and works fine.

    ReplyDelete

Post a Comment

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

Use of req.query, req.params and req.body in NODE JS

How to capture finger prints in java