From 0c06cb0b5832b83ecd31a90f6e66e2ffc948567a Mon Sep 17 00:00:00 2001 From: "mottadelli75@gmail.com" Date: Thu, 27 Dec 2012 22:25:09 +0000 Subject: [PATCH] Add NACK method into IStompClient Interface and manage before/after send frame --- StompClient.pas | 25 +++++++++++++++++++++++++ StompTypes.pas | 2 ++ 2 files changed, 27 insertions(+) diff --git a/StompClient.pas b/StompClient.pas index 19ddd59b..1d097ad6 100644 --- a/StompClient.pas +++ b/StompClient.pas @@ -39,6 +39,8 @@ uses type { TStompClient } + TSenderFrameEvent = procedure (AFrame: IStompFrame) of object; + TStompClient = class(TInterfacedObject, IStompClient) private {$IFDEF USESYNAPSE} @@ -58,6 +60,8 @@ type FServerProtocolVersion: string; FClientAcceptProtocolVersion: TStompAcceptProtocol; FServer: string; + FOnBeforeSendFrame: TSenderFrameEvent; + FOnAfterSendFrame: TSenderFrameEvent; procedure SetReceiptTimeout(const Value: Integer); protected @@ -88,6 +92,8 @@ type procedure Send(QueueOrTopicName: string; TextMessage: string; TransactionIdentifier: string; Headers: IStompHeaders = nil); overload; procedure Ack(const MessageID: string; const TransactionIdentifier: string = ''); + { STOMP 1.1 } + procedure Nack(const MessageID: string; const TransactionIdentifier: string = ''); procedure BeginTransaction(const TransactionIdentifier: string); procedure CommitTransaction(const TransactionIdentifier: string); procedure AbortTransaction(const TransactionIdentifier: string); @@ -101,6 +107,9 @@ type function GetSession: string; property ReceiptTimeout: Integer read FReceiptTimeout write SetReceiptTimeout; property Transactions: TStringList read FTransactions; + //* Manage Events + property OnBeforeSendFrame: TSenderFrameEvent read FOnBeforeSendFrame write FOnBeforeSendFrame; + property OnAfterSendFrame: TSenderFrameEvent read FOnAfterSendFrame write FOnAfterSendFrame; end; implementation @@ -366,6 +375,18 @@ begin end; end; +procedure TStompClient.Nack(const MessageID, TransactionIdentifier: string); +var + Frame: IStompFrame; +begin + Frame := TStompFrame.Create; + Frame.SetCommand('NACK'); + Frame.GetHeaders.Add('message-id', MessageID); + if TransactionIdentifier <> '' then + Frame.GetHeaders.Add('transaction', TransactionIdentifier); + SendFrame(Frame); +end; + procedure TStompClient.Receipt(const ReceiptID: string); var Frame: IStompFrame; @@ -546,10 +567,14 @@ end; procedure TStompClient.SendFrame(AFrame: IStompFrame); begin {$IFDEF USESYNAPSE} + if Assigned(FOnBeforeSendFrame) then FOnBeforeSendFrame(AFrame); FSynapseTCP.SendString(AFrame.output); + if Assigned(FOnAfterSendFrame) then FOnAfterSendFrame(AFrame); {$ELSE} // FTCP.IOHandler.write(TEncoding.ASCII.GetBytes(AFrame.output)); + if Assigned(FOnBeforeSendFrame) then FOnBeforeSendFrame(AFrame); FTCP.IOHandler.write(TEncoding.UTF8.GetBytes(AFrame.output)); + if Assigned(FOnAfterSendFrame) then FOnAfterSendFrame(AFrame); {$ENDIF} end; diff --git a/StompTypes.pas b/StompTypes.pas index 35ff2b2c..1fa8cd9d 100644 --- a/StompTypes.pas +++ b/StompTypes.pas @@ -80,6 +80,8 @@ type procedure Send(QueueOrTopicName: string; TextMessage: string; TransactionIdentifier: string; Headers: IStompHeaders = nil); overload; procedure Ack(const MessageID: string; const TransactionIdentifier: string = ''); + { STOMP 1.1 } + procedure Nack(const MessageID: string; const TransactionIdentifier: string = ''); procedure BeginTransaction(const TransactionIdentifier: string); procedure CommitTransaction(const TransactionIdentifier: string); procedure AbortTransaction(const TransactionIdentifier: string);