Delphi DLL
Delphi DLL
SQS Send Message
See more Amazon SQS Examples
Note: This example requires a patch to work properly. It requires Chilkat v9.5.0.61, which can be obtained upon request to support@chilkatsoft.comDelivers a message to the specified queue. With Amazon SQS, you now have the ability to send large payload messages that are up to 256KB (262,144 bytes) in size.
See SQS SendMessage or detailed information.
Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, AuthAws, Rest, Xml;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
rest: HCkRest;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
authAws: HCkAuthAws;
responseXml: PWideChar;
xml: HCkXml;
begin
success := False;
// Note: This example requires a patch to work properly.
// It requires Chilkat v9.5.0.61, which can be obtained upon request to support@chilkatsoft.com
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest := CkRest_Create();
// Connect to the Amazon AWS REST server.
// such as https://sqs.us-west-2.amazonaws.com/
bTls := True;
port := 443;
bAutoReconnect := True;
success := CkRest_Connect(rest,'sqs.us-west-2.amazonaws.com',port,bTls,bAutoReconnect);
// Provide AWS credentials for the REST call.
authAws := CkAuthAws_Create();
CkAuthAws_putAccessKey(authAws,'AWS_ACCESS_KEY');
CkAuthAws_putSecretKey(authAws,'AWS_SECRET_KEY');
// the region should match our URL above..
CkAuthAws_putRegion(authAws,'us-west-2');
CkAuthAws_putServiceName(authAws,'sqs');
CkRest_SetAuthAws(rest,authAws);
CkRest_AddQueryParam(rest,'Action','SendMessage');
CkRest_AddQueryParam(rest,'MessageBody','This is the message body which can be up to 256K in size.');
CkRest_AddQueryParam(rest,'MessageAttribute.1.Name','test_attribute_name_1');
CkRest_AddQueryParam(rest,'MessageAttribute.1.Value.StringValue','test_attribute_value_1');
CkRest_AddQueryParam(rest,'MessageAttribute.1.Value.DataType','String');
CkRest_AddQueryParam(rest,'MessageAttribute.2.Name','test_attribute_name_2');
CkRest_AddQueryParam(rest,'MessageAttribute.2.Value.StringValue','test_attribute_value_2');
CkRest_AddQueryParam(rest,'MessageAttribute.2.Value.DataType','String');
// Use the actual path part of your SQS queue URL here:
responseXml := CkRest__fullRequestFormUrlEncoded(rest,'POST','/123456789123/chilkatTest');
if (CkRest_getLastMethodSuccess(rest) <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
xml := CkXml_Create();
// A successful response will have a status code equal to 200.
if (CkRest_getResponseStatusCode(rest) <> 200) then
begin
Memo1.Lines.Add('request header = ' + CkRest__lastRequestHeader(rest));
Memo1.Lines.Add('response status code = ' + IntToStr(CkRest_getResponseStatusCode(rest)));
Memo1.Lines.Add('response status text = ' + CkRest__responseStatusText(rest));
Memo1.Lines.Add('response header: ' + CkRest__responseHeader(rest));
CkXml_LoadXml(xml,responseXml);
Memo1.Lines.Add(CkXml__getXml(xml));
Exit;
end;
// Examine the successful XML response.
CkXml_LoadXml(xml,responseXml);
Memo1.Lines.Add(CkXml__getXml(xml));
Memo1.Lines.Add('----');
// A successful response looks like this:
// <?xml version="1.0" encoding="utf-8" ?>
// <SendMessageResponse>
// <SendMessageResult>
// <MD5OfMessageBody>
// fafb00f5732ab283681e124bf8747ed1
// </MD5OfMessageBody>
// <MD5OfMessageAttributes>
// 3ae8f24a165a8cedc005670c81a27295
// </MD5OfMessageAttributes>
// <MessageId>
// 5fea7756-0ea4-451a-a703-a558b933e274
// </MessageId>
// </SendMessageResult>
// <ResponseMetadata>
// <RequestId>
// 27daac76-34dd-47df-bd01-1f6e873584a0
// </RequestId>
// </ResponseMetadata>
// </SendMessageResponse>
// Get some values from the response XML:
Memo1.Lines.Add('Body: ' + CkXml__chilkatPath(xml,'SendMessageResult|MD5OfMessageBody|*'));
Memo1.Lines.Add('MessageId: ' + CkXml__chilkatPath(xml,'SendMessageResult|MessageId|*'));
Memo1.Lines.Add('RequestId: ' + CkXml__chilkatPath(xml,'ResponseMetadata|RequestId|*'));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkXml_Dispose(xml);
end;