Last active
December 21, 2015 18:09
-
-
Save cjmamo/6345631 to your computer and use it in GitHub Desktop.
Bridging Mule and MSMQ with ZeroMQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using ZeroMQ; | |
using System.Messaging; | |
namespace ConsoleApplication | |
{ | |
class Bridge | |
{ | |
static void Main(string[] args) | |
{ | |
//Name of local MSMQ queue | |
string queueName = @".\private$\TestQueue"; | |
MessageQueue queue = null; | |
//Create MSMQ queue if doesn't exist | |
if (!MessageQueue.Exists(queueName)) | |
{ | |
queue = MessageQueue.Create(queueName); | |
} | |
else | |
{ | |
queue = new MessageQueue(queueName); | |
} | |
using (ZmqContext context = ZmqContext.Create()) | |
{ | |
using (ZmqSocket server = context.CreateSocket(SocketType.PULL)) | |
{ | |
//Accept ZeroMQ push messages from all interfaces on port 5555 | |
server.Bind("tcp://*:5555"); | |
while (true) | |
{ | |
//Wait for next message from Mule | |
string message = server.Receive(Encoding.ASCII); | |
Console.WriteLine("Sending to MSMQ: {0}", message); | |
//Dispatch message to MSMQ broker | |
queue.Send(message); | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<mule xmlns="http://www.mulesoft.org/schema/mule/core" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:zmq="http://www.mulesoft.org/schema/mule/zeromq" | |
xmlns:http="http://www.mulesoft.org/schema/mule/http" | |
xsi:schemaLocation=" | |
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd | |
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd | |
http://www.mulesoft.org/schema/mule/zeromq http://www.mulesoft.org/schema/mule/zeromq/current/mule-zeromq.xsd"> | |
<flow name="MsmqFlow"> | |
<http:inbound-endpoint address="http://localhost:8081" /> | |
<zmq:outbound-endpoint address="tcp://localhost:5555" socket-operation="connect" | |
exchange-pattern="push"/> | |
</flow> | |
</mule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment