• 微服务调用(http)


    微服务调用(http)

    微服务可以是http的RESTful API也可以是二进制流服务等。

    restful api调用演示

    procedure TForm2.Button2Click(Sender: TObject);
    //rest 查询
    begin
      var req: TIdMultiPartFormDataStream := TIdMultiPartFormDataStream.Create;
      req.AddFormField('cmd', IntToStr(cmd_query));
      req.AddFormField('accountno', '1');
      req.AddFormField('sql', 'select top 2 * from tunit');
      Memo1.Text := IdHTTP1.Post(FUrl2, req);  //'http://localhost:1580/rest?service=dal';
      req.Free;
      ClientDataSet1.FromJson(Memo1.Text);
    end;
    

     二进制流调用演示

    procedure TForm2.Button1Click(Sender: TObject);
    //msgpack 查询
    begin
      var pack: TMsgPack := TMsgPack.Create;
      pack.Force('cmd').AsInteger := cmd_query;                //命令字
      pack.Force('accountno').AsString := '1';                 //数据库帐套号
      pack.Force('tablenum').AsInteger := 2;                   //查几个表
      pack.Force('sql1').AsString := 'select * from tgoods';
      pack.Force('sql2').AsString := 'select * from tunit';
      var req: TBytesStream := TBytesStream.Create;
      var res: TBytesStream := TBytesStream.Create;
      pack.EncodeToStream(req);
      req.Position := 0;
      IdHTTP1.Post(FUrl, req, res); //'http://localhost:1580/msgpack?service=dal'
      pack.Clear;
      res.Position := 0;
      pack.DecodeFromStream(res);
      if pack.Force('return').AsBoolean then
      begin
        ClientDataSet1.Data := pack.Force('dataset1').AsVariant;
        ClientDataSet2.Data := pack.Force('dataset2').AsVariant;
      end
      else
        ShowMessage(pack.Force('err').AsString);
      pack.Free;
      req.Free;
      res.Free;
    end; 
    二进制流调用url
    http://localhost:1580/msgpack?service=dal
    rest json调用url
    http://localhost:1580/rest?service=dal
    service=dal,表示调用dal微服务

     

  • 相关阅读:
    session的生命周期
    临远的spring security教程
    spring security原理图及其解释
    解决eclipse中出现Resource is out of sync with the file system问题
    从SOA到BFV【普元的一份广告文章】
    普元OA平台介绍
    门户平台
    企业门户平台解决方案
    使用 CAS 在 Tomcat 中实现单点登录
    CAS 跨域原理
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/14437065.html
Copyright © 2020-2023  润新知