Skip to content

Commit

Permalink
General corretions for .net
Browse files Browse the repository at this point in the history
  • Loading branch information
MurilloLazzaretti committed Feb 19, 2021
1 parent ec84865 commit ffc3529
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
8 changes: 4 additions & 4 deletions ZapMQ.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="Win32\Debug\ZapMQ.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<DeployFile LocalName="Win64\Release\ZapMQ.exe" Configuration="Release" Class="ProjectOutput">
<Platform Name="Win64">
<RemoteName>ZapMQ.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="Win64\Release\ZapMQ.exe" Configuration="Release" Class="ProjectOutput">
<Platform Name="Win64">
<DeployFile LocalName="Win32\Debug\ZapMQ.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>ZapMQ.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
Expand Down
6 changes: 3 additions & 3 deletions src/ZapMQ.DataModule.dfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object ZapDataModule: TZapDataModule
OldCreateOrder = False
Height = 245
Width = 176
Height = 272
Width = 220
object Server: TDSServer
AutoStart = False
ChannelQueueSize = 1000
Expand All @@ -21,6 +21,6 @@ object ZapDataModule: TZapDataModule
DSPort = 5679
Filters = <>
Left = 48
Top = 152
Top = 144
end
end
4 changes: 2 additions & 2 deletions src/ZapMQ.DataModule.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface

uses
System.SysUtils, System.Classes, Datasnap.DSCommonServer, Datasnap.DSServer,
IPPeerServer, Datasnap.DSHTTP;
IPPeerServer, Datasnap.DSHTTP, IdHTTPWebBrokerBridge, Datasnap.DSHTTPWebBroker;

type
TZapDataModule = class(TDataModule)
Expand All @@ -14,7 +14,7 @@ TZapDataModule = class(TDataModule)
procedure MethodsGetClass(DSServerClass: TDSServerClass;
var PersistentClass: TPersistentClass);
private
{ Private declarations }

public
{ Public declarations }
end;
Expand Down
12 changes: 12 additions & 0 deletions src/ZapMQ.Message.JSON.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ TZapJSONMessage = class
FId: string;
FRPC: boolean;
FTTL: Word;
FResponse: TJSONObject;
procedure SetBody(const Value: TJSONObject);
procedure SetId(const Value: string);
procedure SetRPC(const Value: boolean);
procedure SetTTL(const Value: Word);
procedure SetResponse(const Value: TJSONObject);
public
property Id : string read FId write SetId;
property Body : TJSONObject read FBody write SetBody;
property RPC : boolean read FRPC write SetRPC;
property TTL : Word read FTTL write SetTTL;
property Response : TJSONObject read FResponse write SetResponse;
function ToJSON : TJSONObject;
destructor Destroy; override;
class function FromJSON(const pJSONString : string) : TZapJSONMessage;
Expand All @@ -37,6 +40,8 @@ destructor TZapJSONMessage.Destroy;
begin
if Assigned(Body) then
Body.Free;
if Assigned(Response) then
Response.Free;
inherited;
end;

Expand Down Expand Up @@ -69,6 +74,11 @@ procedure TZapJSONMessage.SetId(const Value: string);
FId := Value;
end;

procedure TZapJSONMessage.SetResponse(const Value: TJSONObject);
begin
FResponse := Value;
end;

procedure TZapJSONMessage.SetRPC(const Value: boolean);
begin
FRPC := Value;
Expand All @@ -87,6 +97,8 @@ function TZapJSONMessage.ToJSON: TJSONObject;
TEncoding.ASCII.GetBytes(Body.ToString), 0) as TJSONValue);
Result.AddPair('RPC', TJSONBool.Create(FRPC));
Result.AddPair('TTL', TJSONNumber.Create(FTTL));
Result.AddPair('Response', TJSONObject.ParseJSONValue(
TEncoding.ASCII.GetBytes(Response.ToString), 0) as TJSONValue);
end;

end.
5 changes: 5 additions & 0 deletions src/ZapMQ.Message.pas
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ function TZapMessage.Prepare: TZapJSONMessage;
Result.Body := TJSONObject.ParseJSONValue(
TEncoding.ASCII.GetBytes(FBody.ToString), 0) as TJSONObject;
Result.RPC := FRPC;
if Assigned(FResponse) then
begin
Result.Response := TJSONObject.ParseJSONValue(
TEncoding.ASCII.GetBytes(FResponse.ToString), 0) as TJSONObject;
end;
end;

end.
34 changes: 24 additions & 10 deletions src/ZapMQ.Methods.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ interface

uses
System.Classes,
JSON;
JSON,
DataSnap.DSHTTPWebBroker;

type
{$METHODINFO ON}
TZapMethods = class(TComponent)
public
function GetMessage(const pQueueName : string) : string;
function GetRPCResponse(const pQueueName : string; const pIdMessage : string) : string;
function UpdateMessage(const pQueueName : string; pMessage : string) : string;
function UpdateRPCResponse(const pQueueName : string;
const pIdMessage : string; pResponse : string) : string;
function UpdateMessage(const pQueueName : string; const pMessage : string) : string;
function UpdateRPCResponse(const pQueueName : string; const pIdMessage : string;
const pMessage : string) : string;
end;
{$METHODINFO OFF}

Expand Down Expand Up @@ -60,6 +61,8 @@ function TZapMethods.GetRPCResponse(const pQueueName,
var
Queue : TZapQueue;
ZapMessage : TZapMessage;
ZapJSONMessage : TZapJSONMessage;
JSON : TJSONObject;
begin
Result := string.Empty;
Queue := ZapMQ.Core.Context.Queues.Find(pQueueName);
Expand All @@ -70,14 +73,24 @@ function TZapMethods.GetRPCResponse(const pQueueName,
begin
if ZapMessage.Status = zAnswered then
begin
Result := ZapMessage.Response.ToString;
ZapMessage.Status := zSended;
ZapJSONMessage := ZapMessage.Prepare;
try
JSON := ZapJSONMessage.ToJSON;
try
Result := JSON.ToString;
ZapMessage.Status := zSended;
finally
JSON.Free;
end;
finally
ZapJSONMessage.Free;
end;
end;
end;
end;
end;

function TZapMethods.UpdateMessage(const pQueueName : string; pMessage : string) : string;
function TZapMethods.UpdateMessage(const pQueueName : string; const pMessage : string) : string;
var
ZapMessage : TZapMessage;
ZapJSONMessage : TZapJSONMessage;
Expand All @@ -90,15 +103,16 @@ function TZapMethods.UpdateMessage(const pQueueName : string; pMessage : string)
ZapMessage.Body := TJSONObject.ParseJSONValue(
TEncoding.ASCII.GetBytes(ZapJSONMessage.Body.ToString), 0) as TJSONObject;
ZapMessage.RPC := ZapJSONMessage.RPC;
ZapMessage.Response := TJSONObject.Create;
Result := ZapMessage.Id;
ZapMQ.Core.Context.Queues.AddMessage(ZapMessage);
finally
ZapJSONMessage.Free;
end;
end;

function TZapMethods.UpdateRPCResponse(const pQueueName : string;
const pIdMessage : string; pResponse : string): string;
function TZapMethods.UpdateRPCResponse(const pQueueName : string; const pIdMessage : string;
const pMessage : string): string;
var
ZapMessage : TZapMessage;
Queue : TZapQueue;
Expand All @@ -111,7 +125,7 @@ function TZapMethods.UpdateRPCResponse(const pQueueName : string;
if Assigned(ZapMessage) then
begin
ZapMessage.Response := TJSONObject.ParseJSONValue(
TEncoding.ASCII.GetBytes(pResponse), 0) as TJSONObject;
TEncoding.ASCII.GetBytes(pMessage), 0) as TJSONObject;
ZapMessage.Status := zAnswered;
end;
end;
Expand Down

0 comments on commit ffc3529

Please sign in to comment.