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);

}

}

posted @ 2019-06-26 18:00  大P_洲  阅读(2798)  评论(0编辑  收藏  举报