zoukankan      html  css  js  c++  java
  • NETMQ基本用法

    点对点手法消息:request--response

    public void request()

    {

    RequestSocket randomDealer = new RequestSocket();
    randomDealer.Connect("tcp://40.73.1.15:8004");

    randomDealer.SendFrame(DateTime.Now.ToString() + "--yin");
    string aa = randomDealer.ReceiveFrameString();
    Console.Write(aa);
    Thread.Sleep(500);

    }

    public void response()

    {

    ResponseSocket connectingDealer = new ResponseSocket();
    connectingDealer.Bind("tcp://*:" + "8004");

    string msg = connectingDealer.ReceiveFrameString();

    connectingDealer.SendFrame(msg);

    }

    pub--sub发布订阅模式:

    public void pub()

    {

    PublisherSocket publisher = new PublisherSocket();
    publisher.Options.SendHighWatermark = 1000;
    string url = "tcp://*:6663";
    publisher.Bind(url);

    string topicName ="SP-marketdata";
    string str = "hello";
    publisher.SendMoreFrame(topicName).SendFrame(str);

    }

    public void sub()

    {

    var sub = new SubscriberSocket();

    string port = "6663";
    string topicName ="SP-marketdata";
    sub.Connect("tcp://127.0.0.1:" + port);
    sub.Subscribe(topicName);

    while (sub != null)
    {
    //这里要获取2次ReceiveFrameString
    string a = sub.ReceiveFrameString();
    string str = sub.ReceiveFrameString();

    Console.WriteLine(str);

    }

    }

  • 相关阅读:
    0x02 枚举、模拟、递推
    0x01 位运算
    bzoj3529: [Sdoi2014]数表
    bzoj5216: [Lydsy2017省队十连测]公路建设
    POJ1789Truck History
    最小生成树模板
    POJ1258Agri-Net
    POJ1860Currency Exchange(SPFA)
    POJ3083Children of the Candy Corn
    POJ2503Babelfish
  • 原文地址:https://www.cnblogs.com/yinzhou/p/11091491.html
Copyright © 2011-2022 走看看