码迷,mamicode.com
首页 > 其他好文 > 详细

中间件集群协议msgpack

时间:2020-08-05 16:53:29      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:result   beat   UNC   申请   csharp   arp   author   ring   group   

中间件集群协议msgpack

/// <author>cxg 2020-8-5</author>
/// 集群协议
/// broker:代理服务器

unit groupProtocol;

interface

uses
  SysUtils, MsgPack
  ,classes
  ;

const         //命令字
  ConnMiddleWare = 2;
  ConnMiddleWareResp = 52;
  MiddleHeartBeat = 5;
  MiddleHeartBeatResp = 55;

/// <summary>
/// 向broker申请连中间件
/// </summary>
/// <returns></returns>
function connMiddle: TStream;
/// <summary>
/// broket返回可用中间件的ip和port
/// </summary>
/// <param name="status"></param>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <returns></returns>
function connMiddleResp(const status: Boolean; const ip: string; const port: Integer): TStream;
/// <summary>
/// 中间件发送心跳给broker
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <returns></returns>
function middleHeart(const ip: string; const port: Integer): TStream;
/// <summary>
/// broker返回中间件心跳应答
/// </summary>
/// <param name="status"></param>
/// <returns></returns>
function middleHeartResp: TStream;

implementation

function middleHeartResp: TStream;
begin
  var p: TMsgPack := TMsgPack.Create;
  Result := TMemoryStream.Create;
  p.Force(‘cmd‘).AsInteger := MiddleHeartBeatResp;
  p.EncodeToStream(Result);
  p.Free;
end;

function middleHeart(const ip: string; const port: Integer): TStream;
begin
  var p: TMsgPack := TMsgPack.Create;
  Result := TMemoryStream.Create;
  p.Force(‘cmd‘).AsInteger := MiddleHeartBeat;
  p.Force(‘ip‘).AsString := ip;
  p.Force(‘port‘).AsInteger := port;
  p.EncodeToStream(Result);
  p.Free;
end;

function connMiddleResp(const status: Boolean; const ip: string; const port: Integer): TStream;
begin
  var p: TMsgPack := TMsgPack.Create;
  Result := TMemoryStream.Create;
  p.Force(‘cmd‘).AsInteger := ConnMiddleWareResp;
  p.Force(‘status‘).AsBoolean := status;
  p.Force(‘ip‘).AsString := ip;
  p.Force(‘port‘).AsInteger := port;
  p.EncodeToStream(Result);
  p.Free;
end;

function connMiddle: TStream;
begin
  var p: TMsgPack := TMsgPack.Create;
  Result := TMemoryStream.Create;
  p.Force(‘cmd‘).AsInteger := ConnMiddleWare;
  p.EncodeToStream(Result);
  p.Free;
end;

end.

  

中间件集群协议msgpack

标签:result   beat   UNC   申请   csharp   arp   author   ring   group   

原文地址:https://www.cnblogs.com/hnxxcxg/p/13440240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!