Guest User

Home grown forwarder

a guest
Mar 8th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. private void Setup(CancellationToken cancellationToken)
  2. {
  3. using (ZmqSocket frontend = this.Context.CreateSocket(SocketType.SUB), backend = this.Context.CreateSocket(SocketType.PUB))
  4. {
  5. frontend.Bind("tcp://*:5550");
  6. frontend.SubscribeAll();
  7.  
  8. // This is our public endpoint for subscribers
  9. backend.Bind("tcp://*:5553"); // i use local to be able to run the example, this could be the public ip instead eg. tcp://10.1.1.0:8100
  10.  
  11. //var device = new ZeroMQ.Devices.ForwarderDevice(this.Context, "tcp://*:5556", "tcp://*:5555", DeviceMode.Blocking);
  12. //device.Start();
  13. // Shunt messages out to our own subscribers
  14. int i = 0;
  15. try
  16. {
  17. while (true)
  18. {
  19. bool hasMore = true;
  20. var zmqMessage = new ZmqMessage();
  21. while (hasMore)
  22. {
  23. Writeline("waiting on receive frame");
  24. Frame frame = frontend.ReceiveFrame();
  25.  
  26. zmqMessage.Append(new Frame(frame.Buffer));
  27. hasMore = frontend.ReceiveMore;
  28. }
  29. i++;
  30. Writeline(i.ToString());
  31. backend.SendMessage(zmqMessage);
  32. cancellationToken.ThrowIfCancellationRequested();
  33. }
  34. }
  35. catch (Exception ex)
  36. {
  37. Writeline("cancelled gracefully exit " + ex.Message);
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment