-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQS.cfc
162 lines (127 loc) · 3.48 KB
/
SQS.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
*
* @file /f/dev/amazon/SQS.cfc
* @author Manuel H. Mueller [ Onko ] [email protected]
* @description
*
*/
component output="false" displayname="" extends="Connector" {
public function init( required string awsAccessKeyID, required string awsAccessSecret, string endpoint='sqs.eu-west-1.amazonaws.com'){
this.endpoint = endpoint;
this.awsAccessKeyID = awsAccessKeyID;
this.awsAccessSecret = awsAccessSecret;
this.endpoint=endpoint;
this.requestMethod='no-header';
this.version='2011-10-01';
return this;
}
public function CreateQueue(String queueName, array attributes)
{
var body = "Action=CreateQueue";
body &= "QueueName=" & queueName;
for(var i = 1; i<len(attributes); i++)
{
body &= "&Attribute.#i#.Name=" & attributes[i].name;
body &= "&Attribute.#i#.Value=" & attributes[i].value;
}
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod = this.requestMethod,
version = this.version
);
if(result.status == 200)
return getResultNodeValue(result.content, "QueueUrl");
return false;
}
public function ListQueue(String queueNamePrefix)
{
var body = "Action=ListQueues";
body &= "QueueNamePrefix=" & queueNamePrefix;
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod = this.requestMethod,
version = this.version
);
if(result.status == 200)
return getResultNodeValue(result.content, "ListQueuesResult");
//TODO: perepair Result
//--- add Result
return false;
}
public function DeleteQueue()
{
}
private function GetQueueUrl(String queue)
{
var body = "Action=GetQueueUrl&QueueName=" & trim(queue);
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod = this.requestMethod,
version = this.version
);
if(result.status == 200)
{
if(isXML(result.content))
{
var resSt = xmlparse(result.content);
return replacenocase(resSt.GetQueueUrlResponse.GetQueueUrlResult.1.QueueUrl.XmlText,'https://' & this.endPoint,'','all');
}
}
else return false;
dump(var="#result#",label="35|SQS.cfc",format="html",abort=true);
}
public function ReceiveMessage( String queue, limit)
{
var body = "Action=ReceiveMessage";
if(limit)
{
body &= "&MaxNumberOfMessages="& trim(limit);
}
var result = makeRequest (
endpoint=this.endpoint,
uri=GetQueueUrl(queue),
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod = this.requestMethod,
version = this.version
);
if(result.status == 200)
return true;
return false;
}
public function SendMessage(String queue, String message )
{
var body = "Action=SendMessage&MessageBody=" & trim(message);
var result = makeRequest (
endpoint=this.endpoint,
uri=GetQueueUrl(queue),
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod = this.requestMethod,
version = this.version
);
var messageId = 0;
if(isXML(result.content))
{
var resSt = xmlparse(result.content);
messageId = getResultNodeValue(result.content,'MessageId');
}
if(result.status == 200)
return {
messageId: messageId,
status: result.status
}
return result;
}
}