Commit bdaee28d9e39c91626235418e3f4013d0aafbf5d
Committed by
Andrew Shvayka
1 parent
b1bc922d
SQS and SNS Plugins added
Showing
34 changed files
with
1363 additions
and
1 deletions
... | ... | @@ -170,7 +170,7 @@ class RuleActorMessageProcessor extends ComponentMsgProcessor<RuleId> { |
170 | 170 | Optional<RuleToPluginMsg<?>> ruleToPluginMsgOptional = action.convert(ruleCtx, inMsg, inMsgMd); |
171 | 171 | if (ruleToPluginMsgOptional.isPresent()) { |
172 | 172 | RuleToPluginMsg<?> ruleToPluginMsg = ruleToPluginMsgOptional.get(); |
173 | - logger.debug("[{}] Device msg is converter to: {}", entityId, ruleToPluginMsg); | |
173 | + logger.debug("[{}] Device msg is converted to: {}", entityId, ruleToPluginMsg); | |
174 | 174 | context.parent().tell(new RuleToPluginMsgWrapper(pluginTenantId, pluginId, tenantId, entityId, ruleToPluginMsg), context.self()); |
175 | 175 | if (action.isOneWayAction()) { |
176 | 176 | pushToNextRule(context, msg.getCtx(), RuleEngineError.NO_TWO_WAY_ACTIONS); | ... | ... |
extensions/extension-sns/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<!-- | |
3 | + | |
4 | + Copyright © 2016-2017 The Thingsboard Authors | |
5 | + | |
6 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
7 | + you may not use this file except in compliance with the License. | |
8 | + You may obtain a copy of the License at | |
9 | + | |
10 | + http://www.apache.org/licenses/LICENSE-2.0 | |
11 | + | |
12 | + Unless required by applicable law or agreed to in writing, software | |
13 | + distributed under the License is distributed on an "AS IS" BASIS, | |
14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 | + See the License for the specific language governing permissions and | |
16 | + limitations under the License. | |
17 | + | |
18 | +--> | |
19 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | |
20 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
21 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
22 | + <parent> | |
23 | + <artifactId>extensions</artifactId> | |
24 | + <groupId>org.thingsboard</groupId> | |
25 | + <version>1.4.0-SNAPSHOT</version> | |
26 | + </parent> | |
27 | + <modelVersion>4.0.0</modelVersion> | |
28 | + <groupId>org.thingsboard.extensions</groupId> | |
29 | + <artifactId>extension-sns</artifactId> | |
30 | + <packaging>jar</packaging> | |
31 | + | |
32 | + <name>Thingsboard Server SNS Extension</name> | |
33 | + <url>http://thingsboard.org</url> | |
34 | + | |
35 | + <properties> | |
36 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
37 | + <main.dir>${basedir}/../..</main.dir> | |
38 | + <aws.sdk.version>1.11.229</aws.sdk.version> | |
39 | + </properties> | |
40 | + | |
41 | + <dependencies> | |
42 | + <dependency> | |
43 | + <groupId>org.thingsboard</groupId> | |
44 | + <artifactId>extensions-api</artifactId> | |
45 | + <scope>provided</scope> | |
46 | + </dependency> | |
47 | + <dependency> | |
48 | + <groupId>com.amazonaws</groupId> | |
49 | + <artifactId>aws-java-sdk-sns</artifactId> | |
50 | + <version>${aws.sdk.version}</version> | |
51 | + </dependency> | |
52 | + <dependency> | |
53 | + <groupId>org.thingsboard</groupId> | |
54 | + <artifactId>extensions-core</artifactId> | |
55 | + </dependency> | |
56 | + </dependencies> | |
57 | + | |
58 | + <build> | |
59 | + <plugins> | |
60 | + <plugin> | |
61 | + <artifactId>maven-assembly-plugin</artifactId> | |
62 | + <configuration> | |
63 | + <descriptors> | |
64 | + <descriptor>src/assembly/extension.xml</descriptor> | |
65 | + </descriptors> | |
66 | + </configuration> | |
67 | + <executions> | |
68 | + <execution> | |
69 | + <id>make-assembly</id> | |
70 | + <phase>package</phase> | |
71 | + <goals> | |
72 | + <goal>single</goal> | |
73 | + </goals> | |
74 | + </execution> | |
75 | + </executions> | |
76 | + </plugin> | |
77 | + </plugins> | |
78 | + </build> | |
79 | + | |
80 | +</project> | |
\ No newline at end of file | ... | ... |
1 | +<!-- | |
2 | + | |
3 | + Copyright © 2016-2017 The Thingsboard Authors | |
4 | + | |
5 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | + you may not use this file except in compliance with the License. | |
7 | + You may obtain a copy of the License at | |
8 | + | |
9 | + http://www.apache.org/licenses/LICENSE-2.0 | |
10 | + | |
11 | + Unless required by applicable law or agreed to in writing, software | |
12 | + distributed under the License is distributed on an "AS IS" BASIS, | |
13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | + See the License for the specific language governing permissions and | |
15 | + limitations under the License. | |
16 | + | |
17 | +--> | |
18 | +<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" | |
19 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
20 | + xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd"> | |
21 | + <id>extension</id> | |
22 | + <formats> | |
23 | + <format>jar</format> | |
24 | + </formats> | |
25 | + <includeBaseDirectory>false</includeBaseDirectory> | |
26 | + <dependencySets> | |
27 | + <dependencySet> | |
28 | + <outputDirectory>/</outputDirectory> | |
29 | + <useProjectArtifact>true</useProjectArtifact> | |
30 | + <unpack>true</unpack> | |
31 | + <scope>runtime</scope> | |
32 | + <excludes> | |
33 | + | |
34 | + </excludes> | |
35 | + </dependencySet> | |
36 | + </dependencySets> | |
37 | +</assembly> | |
\ No newline at end of file | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sns.action; | |
17 | + | |
18 | +import org.thingsboard.server.common.data.id.CustomerId; | |
19 | +import org.thingsboard.server.common.data.id.DeviceId; | |
20 | +import org.thingsboard.server.common.data.id.TenantId; | |
21 | +import org.thingsboard.server.extensions.api.plugins.msg.AbstractRuleToPluginMsg; | |
22 | + | |
23 | +/** | |
24 | + * Created by Valerii Sosliuk on 11/15/2017. | |
25 | + */ | |
26 | +public class SnsTopicActionMsg extends AbstractRuleToPluginMsg<SnsTopicActionPayload> { | |
27 | + | |
28 | + public SnsTopicActionMsg(TenantId tenantId, CustomerId customerId, DeviceId deviceId, SnsTopicActionPayload payload) { | |
29 | + super(tenantId, customerId, deviceId, payload); | |
30 | + } | |
31 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sns.action; | |
17 | + | |
18 | +import lombok.Builder; | |
19 | +import lombok.Data; | |
20 | +import org.thingsboard.server.common.msg.session.MsgType; | |
21 | + | |
22 | +import java.io.Serializable; | |
23 | + | |
24 | +/** | |
25 | + * Created by Valerii Sosliuk on 11/15/2017. | |
26 | + */ | |
27 | +@Data | |
28 | +@Builder | |
29 | +public class SnsTopicActionPayload implements Serializable { | |
30 | + | |
31 | + private final String topicArn; | |
32 | + private final String msgBody; | |
33 | + | |
34 | + private final Integer requestId; | |
35 | + private final MsgType msgType; | |
36 | + private final boolean sync; | |
37 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sns.action; | |
17 | + | |
18 | +import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | |
19 | +import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | |
20 | +import org.thingsboard.server.extensions.api.component.Action; | |
21 | +import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | |
22 | +import org.thingsboard.server.extensions.api.rules.RuleContext; | |
23 | +import org.thingsboard.server.extensions.core.action.template.AbstractTemplatePluginAction; | |
24 | + | |
25 | +import java.util.Optional; | |
26 | + | |
27 | +/** | |
28 | + * Created by Valerii Sosliuk on 11/15/2017. | |
29 | + */ | |
30 | +@Action(name = "SNS Topic Action", descriptor = "SnsTopicActionDescriptor.json", configuration = SnsTopicPluginActionConfiguration.class) | |
31 | +public class SnsTopicPluginAction extends AbstractTemplatePluginAction<SnsTopicPluginActionConfiguration> { | |
32 | + | |
33 | + @Override | |
34 | + protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, ToDeviceActorMsg msg, FromDeviceRequestMsg payload) { | |
35 | + SnsTopicActionPayload.SnsTopicActionPayloadBuilder builder = SnsTopicActionPayload.builder(); | |
36 | + builder.msgType(payload.getMsgType()); | |
37 | + builder.requestId(payload.getRequestId()); | |
38 | + builder.topicArn(configuration.getTopicArn()); | |
39 | + builder.msgBody(getMsgBody(ctx, msg)); | |
40 | + return Optional.of(new SnsTopicActionMsg(msg.getTenantId(), | |
41 | + msg.getCustomerId(), | |
42 | + msg.getDeviceId(), | |
43 | + builder.build())); | |
44 | + } | |
45 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sns.action; | |
17 | + | |
18 | +import lombok.Data; | |
19 | +import org.thingsboard.server.extensions.core.action.template.TemplateActionConfiguration; | |
20 | + | |
21 | +/** | |
22 | + * Created by Valerii Sosliuk on 11/15/2017. | |
23 | + */ | |
24 | +@Data | |
25 | +public class SnsTopicPluginActionConfiguration implements TemplateActionConfiguration { | |
26 | + | |
27 | + private String topicArn; | |
28 | + private String template; | |
29 | + private boolean sync; | |
30 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sns.plugin; | |
17 | + | |
18 | +import com.amazonaws.services.sns.AmazonSNS; | |
19 | +import com.amazonaws.services.sns.model.PublishRequest; | |
20 | +import com.amazonaws.services.sns.model.PublishResult; | |
21 | +import com.amazonaws.services.sqs.AmazonSQS; | |
22 | +import com.amazonaws.services.sqs.model.SendMessageRequest; | |
23 | +import lombok.RequiredArgsConstructor; | |
24 | +import lombok.extern.slf4j.Slf4j; | |
25 | +import org.thingsboard.server.common.data.id.RuleId; | |
26 | +import org.thingsboard.server.common.data.id.TenantId; | |
27 | +import org.thingsboard.server.common.msg.core.BasicStatusCodeResponse; | |
28 | +import org.thingsboard.server.extensions.api.plugins.PluginContext; | |
29 | +import org.thingsboard.server.extensions.api.plugins.handlers.RuleMsgHandler; | |
30 | +import org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg; | |
31 | +import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | |
32 | +import org.thingsboard.server.extensions.api.rules.RuleException; | |
33 | +import org.thingsboard.server.extensions.sns.action.SnsTopicActionMsg; | |
34 | +import org.thingsboard.server.extensions.sns.action.SnsTopicActionPayload; | |
35 | + | |
36 | +/** | |
37 | + * Created by Valerii Sosliuk on 11/6/2017. | |
38 | + */ | |
39 | +@RequiredArgsConstructor | |
40 | +@Slf4j | |
41 | +public class SnsMessageHandler implements RuleMsgHandler { | |
42 | + | |
43 | + private final AmazonSNS sns; | |
44 | + | |
45 | + @Override | |
46 | + public void process(PluginContext ctx, TenantId tenantId, RuleId ruleId, RuleToPluginMsg<?> msg) throws RuleException { | |
47 | + if (msg instanceof SnsTopicActionMsg) { | |
48 | + SnsTopicActionPayload payload = ((SnsTopicActionMsg) msg).getPayload(); | |
49 | + PublishRequest publishRequest = new PublishRequest() | |
50 | + .withTopicArn(payload.getTopicArn()) | |
51 | + .withMessage(payload.getMsgBody()); | |
52 | + sns.publish(publishRequest); | |
53 | + if (payload.isSync()) { | |
54 | + ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, | |
55 | + BasicStatusCodeResponse.onSuccess(payload.getMsgType(), payload.getRequestId()))); | |
56 | + } | |
57 | + return; | |
58 | + } | |
59 | + throw new RuleException("Unsupported message type " + msg.getClass().getName() + "!"); | |
60 | + | |
61 | + } | |
62 | + | |
63 | +} | ... | ... |
extensions/extension-sns/src/main/java/org/thingsboard/server/extensions/sns/plugin/SnsPlugin.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sns.plugin; | |
17 | + | |
18 | +import com.amazonaws.auth.AWSCredentials; | |
19 | +import com.amazonaws.auth.AWSStaticCredentialsProvider; | |
20 | +import com.amazonaws.auth.BasicAWSCredentials; | |
21 | +import com.amazonaws.services.sns.AmazonSNS; | |
22 | +import com.amazonaws.services.sns.AmazonSNSClient; | |
23 | +import org.thingsboard.server.extensions.api.component.Plugin; | |
24 | +import org.thingsboard.server.extensions.api.plugins.AbstractPlugin; | |
25 | +import org.thingsboard.server.extensions.api.plugins.PluginContext; | |
26 | +import org.thingsboard.server.extensions.api.plugins.handlers.RuleMsgHandler; | |
27 | +import org.thingsboard.server.extensions.sns.action.SnsTopicPluginAction; | |
28 | + | |
29 | +/** | |
30 | + * Created by Valerii Sosliuk on 11/15/2017. | |
31 | + */ | |
32 | +@Plugin(name = "SNS Plugin", actions = {SnsTopicPluginAction.class}, | |
33 | + descriptor = "SnsPluginDescriptor.json", configuration = SnsPluginConfiguration.class) | |
34 | +public class SnsPlugin extends AbstractPlugin<SnsPluginConfiguration> { | |
35 | + | |
36 | + private SnsMessageHandler snsMessageHandler; | |
37 | + private SnsPluginConfiguration configuration; | |
38 | + | |
39 | + @Override | |
40 | + public void init(SnsPluginConfiguration configuration) { | |
41 | + this.configuration = configuration; | |
42 | + init(); | |
43 | + } | |
44 | + | |
45 | + private void init() { | |
46 | + AWSCredentials awsCredentials = new BasicAWSCredentials(configuration.getAccessKeyId(), configuration.getSecretAccessKey()); | |
47 | + AWSStaticCredentialsProvider credProvider = new AWSStaticCredentialsProvider(awsCredentials); | |
48 | + AmazonSNS sns = AmazonSNSClient.builder() | |
49 | + .withCredentials(credProvider) | |
50 | + .withRegion(configuration.getRegion()) | |
51 | + .build(); | |
52 | + this.snsMessageHandler = new SnsMessageHandler(sns); | |
53 | + | |
54 | + } | |
55 | + | |
56 | + private void destroy() { | |
57 | + this.snsMessageHandler = null; | |
58 | + } | |
59 | + | |
60 | + @Override | |
61 | + protected RuleMsgHandler getRuleMsgHandler() { | |
62 | + return snsMessageHandler; | |
63 | + } | |
64 | + | |
65 | + @Override | |
66 | + public void resume(PluginContext ctx) { | |
67 | + init(); | |
68 | + } | |
69 | + | |
70 | + @Override | |
71 | + public void suspend(PluginContext ctx) { | |
72 | + destroy(); | |
73 | + } | |
74 | + | |
75 | + @Override | |
76 | + public void stop(PluginContext ctx) { | |
77 | + destroy(); | |
78 | + } | |
79 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sns.plugin; | |
17 | + | |
18 | +import lombok.Data; | |
19 | + | |
20 | +/** | |
21 | + * Created by Valerii Sosliuk on 11/5/2017. | |
22 | + */ | |
23 | +@Data | |
24 | +public class SnsPluginConfiguration { | |
25 | + | |
26 | + private String accessKeyId; | |
27 | + private String secretAccessKey; | |
28 | + private String region; | |
29 | + | |
30 | +} | ... | ... |
1 | +{ | |
2 | + "schema": { | |
3 | + "title": "SNS Plugin Configuration", | |
4 | + "type": "object", | |
5 | + "properties": { | |
6 | + "accessKeyId": { | |
7 | + "title": "Access Key ID", | |
8 | + "type": "string" | |
9 | + }, | |
10 | + "secretAccessKey": { | |
11 | + "title": "Secret Access Key", | |
12 | + "type": "string" | |
13 | + }, | |
14 | + "region": { | |
15 | + "title": "Region", | |
16 | + "type": "string" | |
17 | + } | |
18 | + }, | |
19 | + "required": [ | |
20 | + "accessKeyId", | |
21 | + "secretAccessKey", | |
22 | + "region" | |
23 | + ] | |
24 | + }, | |
25 | + "form": [ | |
26 | + "accessKeyId", | |
27 | + "secretAccessKey", | |
28 | + "region" | |
29 | + ] | |
30 | +} | |
\ No newline at end of file | ... | ... |
1 | +{ | |
2 | + "schema": { | |
3 | + "title": "SNS Topic Action Configuration", | |
4 | + "type": "object", | |
5 | + "properties": { | |
6 | + "sync": { | |
7 | + "title": "Requires delivery confirmation", | |
8 | + "type": "boolean" | |
9 | + }, | |
10 | + "topicArn": { | |
11 | + "title": "Topic ARN", | |
12 | + "type": "string" | |
13 | + }, | |
14 | + "template": { | |
15 | + "title": "Body Template", | |
16 | + "type": "string" | |
17 | + } | |
18 | + }, | |
19 | + "required": [ | |
20 | + "sync", | |
21 | + "topicArn", | |
22 | + "template" | |
23 | + ] | |
24 | + }, | |
25 | + "form": [ | |
26 | + "sync", | |
27 | + "topicArn", | |
28 | + { | |
29 | + "key": "template", | |
30 | + "type": "textarea", | |
31 | + "rows": 5 | |
32 | + } | |
33 | + ] | |
34 | +} | |
\ No newline at end of file | ... | ... |
extensions/extention-sqs/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<!-- | |
3 | + | |
4 | + Copyright © 2016-2017 The Thingsboard Authors | |
5 | + | |
6 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
7 | + you may not use this file except in compliance with the License. | |
8 | + You may obtain a copy of the License at | |
9 | + | |
10 | + http://www.apache.org/licenses/LICENSE-2.0 | |
11 | + | |
12 | + Unless required by applicable law or agreed to in writing, software | |
13 | + distributed under the License is distributed on an "AS IS" BASIS, | |
14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 | + See the License for the specific language governing permissions and | |
16 | + limitations under the License. | |
17 | + | |
18 | +--> | |
19 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | |
20 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
21 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
22 | + <parent> | |
23 | + <artifactId>extensions</artifactId> | |
24 | + <groupId>org.thingsboard</groupId> | |
25 | + <version>1.4.0-SNAPSHOT</version> | |
26 | + </parent> | |
27 | + <modelVersion>4.0.0</modelVersion> | |
28 | + <groupId>org.thingsboard.extensions</groupId> | |
29 | + <artifactId>extension-sqs</artifactId> | |
30 | + <packaging>jar</packaging> | |
31 | + | |
32 | + <name>Thingsboard Server SQS Extension</name> | |
33 | + <url>http://thingsboard.org</url> | |
34 | + | |
35 | + <properties> | |
36 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
37 | + <main.dir>${basedir}/../..</main.dir> | |
38 | + <aws.sdk.version>1.11.229</aws.sdk.version> | |
39 | + </properties> | |
40 | + | |
41 | + <dependencies> | |
42 | + <dependency> | |
43 | + <groupId>org.thingsboard</groupId> | |
44 | + <artifactId>extensions-api</artifactId> | |
45 | + <scope>provided</scope> | |
46 | + </dependency> | |
47 | + <dependency> | |
48 | + <groupId>com.amazonaws</groupId> | |
49 | + <artifactId>aws-java-sdk-sqs</artifactId> | |
50 | + <version>${aws.sdk.version}</version> | |
51 | + </dependency> | |
52 | + <dependency> | |
53 | + <groupId>org.thingsboard</groupId> | |
54 | + <artifactId>extensions-core</artifactId> | |
55 | + </dependency> | |
56 | + </dependencies> | |
57 | + | |
58 | + <build> | |
59 | + <plugins> | |
60 | + <plugin> | |
61 | + <artifactId>maven-assembly-plugin</artifactId> | |
62 | + <configuration> | |
63 | + <descriptors> | |
64 | + <descriptor>src/assembly/extension.xml</descriptor> | |
65 | + </descriptors> | |
66 | + </configuration> | |
67 | + <executions> | |
68 | + <execution> | |
69 | + <id>make-assembly</id> | |
70 | + <phase>package</phase> | |
71 | + <goals> | |
72 | + <goal>single</goal> | |
73 | + </goals> | |
74 | + </execution> | |
75 | + </executions> | |
76 | + </plugin> | |
77 | + </plugins> | |
78 | + </build> | |
79 | + | |
80 | +</project> | |
\ No newline at end of file | ... | ... |
1 | +<!-- | |
2 | + | |
3 | + Copyright © 2016-2017 The Thingsboard Authors | |
4 | + | |
5 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | + you may not use this file except in compliance with the License. | |
7 | + You may obtain a copy of the License at | |
8 | + | |
9 | + http://www.apache.org/licenses/LICENSE-2.0 | |
10 | + | |
11 | + Unless required by applicable law or agreed to in writing, software | |
12 | + distributed under the License is distributed on an "AS IS" BASIS, | |
13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | + See the License for the specific language governing permissions and | |
15 | + limitations under the License. | |
16 | + | |
17 | +--> | |
18 | +<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" | |
19 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
20 | + xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd"> | |
21 | + <id>extension</id> | |
22 | + <formats> | |
23 | + <format>jar</format> | |
24 | + </formats> | |
25 | + <includeBaseDirectory>false</includeBaseDirectory> | |
26 | + <dependencySets> | |
27 | + <dependencySet> | |
28 | + <outputDirectory>/</outputDirectory> | |
29 | + <useProjectArtifact>true</useProjectArtifact> | |
30 | + <unpack>true</unpack> | |
31 | + <scope>runtime</scope> | |
32 | + <excludes> | |
33 | + | |
34 | + </excludes> | |
35 | + </dependencySet> | |
36 | + </dependencySets> | |
37 | +</assembly> | |
\ No newline at end of file | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs.action.fifo; | |
17 | + | |
18 | +import org.thingsboard.server.common.data.id.CustomerId; | |
19 | +import org.thingsboard.server.common.data.id.DeviceId; | |
20 | +import org.thingsboard.server.common.data.id.TenantId; | |
21 | +import org.thingsboard.server.extensions.api.plugins.msg.AbstractRuleToPluginMsg; | |
22 | + | |
23 | +/** | |
24 | + * Created by Valerii Sosliuk on 11/10/2017. | |
25 | + */ | |
26 | +public class SqsFifoQueueActionMsg extends AbstractRuleToPluginMsg<SqsFifoQueueActionPayload> { | |
27 | + | |
28 | + public SqsFifoQueueActionMsg(TenantId tenantId, CustomerId customerId, DeviceId deviceId, SqsFifoQueueActionPayload payload) { | |
29 | + super(tenantId, customerId, deviceId, payload); | |
30 | + } | |
31 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs.action.fifo; | |
17 | + | |
18 | +import lombok.Builder; | |
19 | +import lombok.Data; | |
20 | +import org.thingsboard.server.common.msg.session.MsgType; | |
21 | + | |
22 | +import java.io.Serializable; | |
23 | + | |
24 | +/** | |
25 | + * Created by Valerii Sosliuk on 11/10/2017. | |
26 | + */ | |
27 | +@Data | |
28 | +@Builder | |
29 | +public class SqsFifoQueueActionPayload implements Serializable { | |
30 | + | |
31 | + private final String queue; | |
32 | + private final String msgBody; | |
33 | + private final String deviceId; | |
34 | + | |
35 | + private final Integer requestId; | |
36 | + private final MsgType msgType; | |
37 | + private final boolean sync; | |
38 | + | |
39 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs.action.fifo; | |
17 | + | |
18 | +import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | |
19 | +import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | |
20 | +import org.thingsboard.server.extensions.api.component.Action; | |
21 | +import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | |
22 | +import org.thingsboard.server.extensions.api.rules.RuleContext; | |
23 | +import org.thingsboard.server.extensions.core.action.template.AbstractTemplatePluginAction; | |
24 | +import org.thingsboard.server.extensions.sqs.action.standard.SqsStandardQueueActionMsg; | |
25 | +import org.thingsboard.server.extensions.sqs.action.standard.SqsStandardQueueActionPayload; | |
26 | +import org.thingsboard.server.extensions.sqs.action.standard.SqsStandardQueuePluginActionConfiguration; | |
27 | + | |
28 | +import java.util.Optional; | |
29 | + | |
30 | +/** | |
31 | + * Created by Valerii Sosliuk on 11/5/2017. | |
32 | + */ | |
33 | +@Action(name = "SQS Fifo Queue Action", descriptor = "SqsFifoQueueActionDescriptor.json", configuration = SqsFifoQueuePluginActionConfiguration.class) | |
34 | +public class SqsFifoQueuePluginAction extends AbstractTemplatePluginAction<SqsFifoQueuePluginActionConfiguration> { | |
35 | + | |
36 | + @Override | |
37 | + protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, ToDeviceActorMsg msg, FromDeviceRequestMsg payload) { | |
38 | + SqsFifoQueueActionPayload.SqsFifoQueueActionPayloadBuilder builder = SqsFifoQueueActionPayload.builder(); | |
39 | + builder.msgType(payload.getMsgType()); | |
40 | + builder.requestId(payload.getRequestId()); | |
41 | + builder.queue(configuration.getQueue()); | |
42 | + builder.deviceId(msg.getDeviceId().toString()); | |
43 | + builder.msgBody(getMsgBody(ctx, msg)); | |
44 | + return Optional.of(new SqsFifoQueueActionMsg(msg.getTenantId(), | |
45 | + msg.getCustomerId(), | |
46 | + msg.getDeviceId(), | |
47 | + builder.build())); | |
48 | + } | |
49 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs.action.fifo; | |
17 | + | |
18 | +import lombok.Data; | |
19 | +import org.thingsboard.server.extensions.core.action.template.TemplateActionConfiguration; | |
20 | + | |
21 | +/** | |
22 | + * Created by Valerii Sosliuk on 11/10/2017. | |
23 | + */ | |
24 | +@Data | |
25 | +public class SqsFifoQueuePluginActionConfiguration implements TemplateActionConfiguration { | |
26 | + | |
27 | + private String queue; | |
28 | + private String template; | |
29 | + private boolean sync; | |
30 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs.action.standard; | |
17 | + | |
18 | +import org.thingsboard.server.common.data.id.CustomerId; | |
19 | +import org.thingsboard.server.common.data.id.DeviceId; | |
20 | +import org.thingsboard.server.common.data.id.TenantId; | |
21 | +import org.thingsboard.server.extensions.api.plugins.msg.AbstractRuleToPluginMsg; | |
22 | + | |
23 | +/** | |
24 | + * Created by Valerii Sosliuk on 11/6/2017. | |
25 | + */ | |
26 | +public class SqsStandardQueueActionMsg extends AbstractRuleToPluginMsg<SqsStandardQueueActionPayload> { | |
27 | + | |
28 | + public SqsStandardQueueActionMsg(TenantId tenantId, CustomerId customerId, DeviceId deviceId, SqsStandardQueueActionPayload payload) { | |
29 | + super(tenantId, customerId, deviceId, payload); | |
30 | + } | |
31 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs.action.standard; | |
17 | + | |
18 | +import lombok.Builder; | |
19 | +import lombok.Data; | |
20 | +import org.thingsboard.server.common.msg.session.MsgType; | |
21 | + | |
22 | +import java.io.Serializable; | |
23 | + | |
24 | +/** | |
25 | + * Created by Valerii Sosliuk on 11/6/2017. | |
26 | + */ | |
27 | +@Data | |
28 | +@Builder | |
29 | +public class SqsStandardQueueActionPayload implements Serializable { | |
30 | + | |
31 | + private final String queue; | |
32 | + private final String msgBody; | |
33 | + private final int delaySeconds; | |
34 | + | |
35 | + private final Integer requestId; | |
36 | + private final MsgType msgType; | |
37 | + private final boolean sync; | |
38 | + | |
39 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs.action.standard; | |
17 | + | |
18 | +import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | |
19 | +import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | |
20 | +import org.thingsboard.server.extensions.api.component.Action; | |
21 | +import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | |
22 | +import org.thingsboard.server.extensions.api.rules.RuleContext; | |
23 | +import org.thingsboard.server.extensions.core.action.template.AbstractTemplatePluginAction; | |
24 | + | |
25 | +import java.util.Optional; | |
26 | + | |
27 | +/** | |
28 | + * Created by Valerii Sosliuk on 11/5/2017. | |
29 | + */ | |
30 | +@Action(name = "SQS Standard Queue Action", descriptor = "SqsStandardQueueActionDescriptor.json", configuration = SqsStandardQueuePluginActionConfiguration.class) | |
31 | +public class SqsStandardQueuePluginAction extends AbstractTemplatePluginAction<SqsStandardQueuePluginActionConfiguration> { | |
32 | + | |
33 | + @Override | |
34 | + protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, ToDeviceActorMsg msg, FromDeviceRequestMsg payload) { | |
35 | + SqsStandardQueueActionPayload.SqsStandardQueueActionPayloadBuilder builder = SqsStandardQueueActionPayload.builder(); | |
36 | + builder.msgType(payload.getMsgType()); | |
37 | + builder.requestId(payload.getRequestId()); | |
38 | + builder.queue(configuration.getQueue()); | |
39 | + builder.delaySeconds(configuration.getDelaySeconds()); | |
40 | + builder.msgBody(getMsgBody(ctx, msg)); | |
41 | + return Optional.of(new SqsStandardQueueActionMsg(msg.getTenantId(), | |
42 | + msg.getCustomerId(), | |
43 | + msg.getDeviceId(), | |
44 | + builder.build())); | |
45 | + } | |
46 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs.action.standard; | |
17 | + | |
18 | +import lombok.Data; | |
19 | +import org.thingsboard.server.extensions.core.action.template.TemplateActionConfiguration; | |
20 | + | |
21 | +/** | |
22 | + * Created by Valerii Sosliuk on 11/6/2017. | |
23 | + */ | |
24 | +@Data | |
25 | +public class SqsStandardQueuePluginActionConfiguration implements TemplateActionConfiguration { | |
26 | + | |
27 | + private String queue; | |
28 | + private int delaySeconds; | |
29 | + private boolean sync; | |
30 | + private String template; | |
31 | + | |
32 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs.plugin; | |
17 | + | |
18 | +import com.amazonaws.services.sqs.AmazonSQS; | |
19 | +import com.amazonaws.services.sqs.model.SendMessageRequest; | |
20 | +import com.amazonaws.services.sqs.model.SendMessageResult; | |
21 | +import lombok.RequiredArgsConstructor; | |
22 | +import lombok.extern.slf4j.Slf4j; | |
23 | +import org.thingsboard.server.common.data.id.RuleId; | |
24 | +import org.thingsboard.server.common.data.id.TenantId; | |
25 | +import org.thingsboard.server.common.msg.core.BasicStatusCodeResponse; | |
26 | +import org.thingsboard.server.extensions.api.plugins.PluginContext; | |
27 | +import org.thingsboard.server.extensions.api.plugins.handlers.RuleMsgHandler; | |
28 | +import org.thingsboard.server.extensions.api.plugins.msg.AbstractRuleToPluginMsg; | |
29 | +import org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg; | |
30 | +import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | |
31 | +import org.thingsboard.server.extensions.api.rules.RuleException; | |
32 | +import org.thingsboard.server.extensions.sqs.action.fifo.SqsFifoQueueActionMsg; | |
33 | +import org.thingsboard.server.extensions.sqs.action.fifo.SqsFifoQueueActionPayload; | |
34 | +import org.thingsboard.server.extensions.sqs.action.standard.SqsStandardQueueActionMsg; | |
35 | +import org.thingsboard.server.extensions.sqs.action.standard.SqsStandardQueueActionPayload; | |
36 | + | |
37 | +/** | |
38 | + * Created by Valerii Sosliuk on 11/15/2017. | |
39 | + */ | |
40 | +@RequiredArgsConstructor | |
41 | +@Slf4j | |
42 | +public class SqsMessageHandler implements RuleMsgHandler { | |
43 | + | |
44 | + private final AmazonSQS sqs; | |
45 | + | |
46 | + @Override | |
47 | + public void process(PluginContext ctx, TenantId tenantId, RuleId ruleId, RuleToPluginMsg<?> msg) throws RuleException { | |
48 | + if (msg instanceof SqsStandardQueueActionMsg) { | |
49 | + sendMessageToStandardQueue(ctx, tenantId, ruleId, msg); | |
50 | + return; | |
51 | + } | |
52 | + if (msg instanceof SqsFifoQueueActionMsg) { | |
53 | + sendMessageToFifoQueue(ctx, tenantId, ruleId, msg); | |
54 | + return; | |
55 | + } | |
56 | + throw new RuleException("Unsupported message type " + msg.getClass().getName() + "!"); | |
57 | + } | |
58 | + | |
59 | + private void sendMessageToStandardQueue(PluginContext ctx, TenantId tenantId, RuleId ruleId, RuleToPluginMsg<?> msg) { | |
60 | + SqsStandardQueueActionPayload payload = ((SqsStandardQueueActionMsg) msg).getPayload(); | |
61 | + SendMessageRequest sendMsgRequest = new SendMessageRequest() | |
62 | + .withDelaySeconds(payload.getDelaySeconds()) | |
63 | + .withQueueUrl(payload.getQueue()) | |
64 | + .withMessageBody(payload.getMsgBody()); | |
65 | + sqs.sendMessage(sendMsgRequest); | |
66 | + if (payload.isSync()) { | |
67 | + ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, | |
68 | + BasicStatusCodeResponse.onSuccess(payload.getMsgType(), payload.getRequestId()))); | |
69 | + } | |
70 | + } | |
71 | + | |
72 | + private void sendMessageToFifoQueue(PluginContext ctx, TenantId tenantId, RuleId ruleId, RuleToPluginMsg<?> msg) { | |
73 | + SqsFifoQueueActionPayload payload = ((SqsFifoQueueActionMsg) msg).getPayload(); | |
74 | + SendMessageRequest sendMsgRequest = new SendMessageRequest() | |
75 | + .withQueueUrl(payload.getQueue()) | |
76 | + .withMessageBody(payload.getMsgBody()) | |
77 | + .withMessageGroupId(payload.getDeviceId()); | |
78 | + sqs.sendMessage(sendMsgRequest); | |
79 | + if (payload.isSync()) { | |
80 | + ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, | |
81 | + BasicStatusCodeResponse.onSuccess(payload.getMsgType(), payload.getRequestId()))); | |
82 | + } | |
83 | + } | |
84 | +} | ... | ... |
extensions/extention-sqs/src/main/java/org/thingsboard/server/extensions/sqs/plugin/SqsPlugin.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs.plugin; | |
17 | + | |
18 | +import com.amazonaws.auth.AWSCredentials; | |
19 | +import com.amazonaws.auth.AWSStaticCredentialsProvider; | |
20 | +import com.amazonaws.auth.BasicAWSCredentials; | |
21 | +import com.amazonaws.regions.Regions; | |
22 | +import com.amazonaws.services.sqs.AmazonSQS; | |
23 | +import com.amazonaws.services.sqs.AmazonSQSClientBuilder; | |
24 | +import org.thingsboard.server.extensions.api.component.Plugin; | |
25 | +import org.thingsboard.server.extensions.api.plugins.AbstractPlugin; | |
26 | +import org.thingsboard.server.extensions.api.plugins.PluginContext; | |
27 | +import org.thingsboard.server.extensions.api.plugins.handlers.RuleMsgHandler; | |
28 | +import org.thingsboard.server.extensions.sqs.action.fifo.SqsFifoQueuePluginAction; | |
29 | +import org.thingsboard.server.extensions.sqs.action.standard.SqsStandardQueuePluginAction; | |
30 | + | |
31 | +/** | |
32 | + * Created by Valerii Sosliuk on 11/6/2017. | |
33 | + */ | |
34 | +@Plugin(name = "SQS Plugin", actions = {SqsStandardQueuePluginAction.class, SqsFifoQueuePluginAction.class}, | |
35 | + descriptor = "SqsPluginDescriptor.json", configuration = SqsPluginConfiguration.class) | |
36 | +public class SqsPlugin extends AbstractPlugin<SqsPluginConfiguration> { | |
37 | + | |
38 | + private SqsMessageHandler sqsMessageHandler; | |
39 | + private SqsPluginConfiguration configuration; | |
40 | + | |
41 | + @Override | |
42 | + public void init(SqsPluginConfiguration configuration) { | |
43 | + this.configuration = configuration; | |
44 | + init(); | |
45 | + } | |
46 | + | |
47 | + private void init() { | |
48 | + AWSCredentials awsCredentials = new BasicAWSCredentials(configuration.getAccessKeyId(), configuration.getSecretAccessKey()); | |
49 | + AmazonSQS sqs = AmazonSQSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) | |
50 | + .withRegion(Regions.fromName(configuration.getRegion())).build(); | |
51 | + this.sqsMessageHandler = new SqsMessageHandler(sqs); | |
52 | + | |
53 | + } | |
54 | + | |
55 | + private void destroy() { | |
56 | + this.sqsMessageHandler = null; | |
57 | + } | |
58 | + | |
59 | + @Override | |
60 | + protected RuleMsgHandler getRuleMsgHandler() { | |
61 | + return sqsMessageHandler; | |
62 | + } | |
63 | + | |
64 | + @Override | |
65 | + public void resume(PluginContext ctx) { | |
66 | + init(); | |
67 | + } | |
68 | + | |
69 | + @Override | |
70 | + public void suspend(PluginContext ctx) { | |
71 | + destroy(); | |
72 | + } | |
73 | + | |
74 | + @Override | |
75 | + public void stop(PluginContext ctx) { | |
76 | + destroy(); | |
77 | + } | |
78 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs.plugin; | |
17 | + | |
18 | +import lombok.Data; | |
19 | + | |
20 | +/** | |
21 | + * Created by Valerii Sosliuk on 11/5/2017. | |
22 | + */ | |
23 | +@Data | |
24 | +public class SqsPluginConfiguration { | |
25 | + | |
26 | + private String accessKeyId; | |
27 | + private String secretAccessKey; | |
28 | + private String region; | |
29 | + | |
30 | +} | ... | ... |
1 | +{ | |
2 | + "schema": { | |
3 | + "title": "SQS FIFO Queue Action Configuration", | |
4 | + "type": "object", | |
5 | + "properties": { | |
6 | + "sync": { | |
7 | + "title": "Requires delivery confirmation", | |
8 | + "type": "boolean" | |
9 | + }, | |
10 | + "queue": { | |
11 | + "title": "Queue URL", | |
12 | + "type": "string" | |
13 | + }, | |
14 | + "template": { | |
15 | + "title": "Body Template", | |
16 | + "type": "string" | |
17 | + } | |
18 | + }, | |
19 | + "required": [ | |
20 | + "sync", | |
21 | + "queue", | |
22 | + "template" | |
23 | + ] | |
24 | + }, | |
25 | + "form": [ | |
26 | + "sync", | |
27 | + "queue", | |
28 | + { | |
29 | + "key": "template", | |
30 | + "type": "textarea", | |
31 | + "rows": 5 | |
32 | + } | |
33 | + ] | |
34 | +} | |
\ No newline at end of file | ... | ... |
1 | +{ | |
2 | + "schema": { | |
3 | + "title": "SQS Plugin Configuration", | |
4 | + "type": "object", | |
5 | + "properties": { | |
6 | + "accessKeyId": { | |
7 | + "title": "Access Key ID", | |
8 | + "type": "string" | |
9 | + }, | |
10 | + "secretAccessKey": { | |
11 | + "title": "Secret Access Key", | |
12 | + "type": "string" | |
13 | + }, | |
14 | + "region": { | |
15 | + "title": "Region", | |
16 | + "type": "string" | |
17 | + } | |
18 | + }, | |
19 | + "required": [ | |
20 | + "accessKeyId", | |
21 | + "secretAccessKey", | |
22 | + "region" | |
23 | + ] | |
24 | + }, | |
25 | + "form": [ | |
26 | + "accessKeyId", | |
27 | + "secretAccessKey", | |
28 | + "region" | |
29 | + ] | |
30 | +} | |
\ No newline at end of file | ... | ... |
1 | +{ | |
2 | + "schema": { | |
3 | + "title": "SQS Standard Queue Action Configuration", | |
4 | + "type": "object", | |
5 | + "properties": { | |
6 | + "sync": { | |
7 | + "title": "Requires delivery confirmation", | |
8 | + "type": "boolean" | |
9 | + }, | |
10 | + "queue": { | |
11 | + "title": "Queue URL", | |
12 | + "type": "string" | |
13 | + }, | |
14 | + "delaySeconds": { | |
15 | + "title": "Delay Seconds", | |
16 | + "type": "integer", | |
17 | + "default": 0 | |
18 | + }, | |
19 | + "template": { | |
20 | + "title": "Body Template", | |
21 | + "type": "string" | |
22 | + } | |
23 | + }, | |
24 | + "required": [ | |
25 | + "sync", | |
26 | + "queue", | |
27 | + "delaySeconds", | |
28 | + "template" | |
29 | + ] | |
30 | + }, | |
31 | + "form": [ | |
32 | + "sync", | |
33 | + "queue", | |
34 | + "delaySeconds", | |
35 | + { | |
36 | + "key": "template", | |
37 | + "type": "textarea", | |
38 | + "rows": 5 | |
39 | + } | |
40 | + ] | |
41 | +} | |
\ No newline at end of file | ... | ... |
extensions/extention-sqs/src/test/java/org/thingsboard/server/extensions/sqs/SqsDemoClient.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2017 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.extensions.sqs; | |
17 | + | |
18 | +import com.amazonaws.auth.AWSCredentials; | |
19 | +import com.amazonaws.auth.AWSStaticCredentialsProvider; | |
20 | +import com.amazonaws.auth.BasicAWSCredentials; | |
21 | +import com.amazonaws.regions.Regions; | |
22 | +import com.amazonaws.services.sqs.AmazonSQS; | |
23 | +import com.amazonaws.services.sqs.AmazonSQSClientBuilder; | |
24 | +import com.amazonaws.services.sqs.model.DeleteMessageRequest; | |
25 | +import com.amazonaws.services.sqs.model.Message; | |
26 | +import lombok.extern.slf4j.Slf4j; | |
27 | + | |
28 | +import java.util.List; | |
29 | + | |
30 | +/** | |
31 | + * Created by Valerii Sosliuk on 11/10/2017. | |
32 | + */ | |
33 | +@Slf4j | |
34 | +public class SqsDemoClient { | |
35 | + | |
36 | + private static final String ACCESS_KEY_ID = "$ACCES_KEY_ID"; | |
37 | + private static final String SECRET_ACCESS_KEY = "$SECRET_ACCESS_KEY"; | |
38 | + | |
39 | + private static final String QUEUE_URL = "$QUEUE_URL"; | |
40 | + private static final String REGION = "us-east-1"; | |
41 | + | |
42 | + public static void main(String[] args) { | |
43 | + log.info("Starting SQS Demo Clinent..."); | |
44 | + AWSCredentials awsCredentials = new BasicAWSCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY); | |
45 | + AmazonSQS sqs = AmazonSQSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) | |
46 | + .withRegion(Regions.fromName(REGION)).build(); | |
47 | + SqsDemoClient client = new SqsDemoClient(); | |
48 | + client.pollMessages(sqs); | |
49 | + } | |
50 | + | |
51 | + private void pollMessages(AmazonSQS sqs) { | |
52 | + log.info("Polling messages"); | |
53 | + while (true) { | |
54 | + List<Message> messages = sqs.receiveMessage(QUEUE_URL).getMessages(); | |
55 | + messages.forEach(m -> { | |
56 | + log.info("Message Received: " + m.getBody()); | |
57 | + System.out.println(m.getBody()); | |
58 | + DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(QUEUE_URL, m.getReceiptHandle()); | |
59 | + sqs.deleteMessage(deleteMessageRequest); | |
60 | + }); | |
61 | + try { | |
62 | + Thread.sleep(1000); | |
63 | + } catch (InterruptedException e) { | |
64 | + Thread.currentThread().interrupt(); | |
65 | + e.printStackTrace(); | |
66 | + } | |
67 | + } | |
68 | + } | |
69 | +} | ... | ... |
1 | +<configuration> | |
2 | + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | |
3 | + <encoder> | |
4 | + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | |
5 | + </encoder> | |
6 | + </appender> | |
7 | + <root level="INFO"> | |
8 | + <appender-ref ref="STDOUT"/> | |
9 | + </root> | |
10 | +</configuration> | |
\ No newline at end of file | ... | ... |
... | ... | @@ -351,6 +351,18 @@ |
351 | 351 | <version>${project.version}</version> |
352 | 352 | </dependency> |
353 | 353 | <dependency> |
354 | + <groupId>org.thingsboard.extensions</groupId> | |
355 | + <artifactId>extension-sqs</artifactId> | |
356 | + <classifier>extension</classifier> | |
357 | + <version>${project.version}</version> | |
358 | + </dependency> | |
359 | + <dependency> | |
360 | + <groupId>org.thingsboard.extensions</groupId> | |
361 | + <artifactId>extension-sns</artifactId> | |
362 | + <classifier>extension</classifier> | |
363 | + <version>${project.version}</version> | |
364 | + </dependency> | |
365 | + <dependency> | |
354 | 366 | <groupId>org.thingsboard.common</groupId> |
355 | 367 | <artifactId>data</artifactId> |
356 | 368 | <version>${project.version}</version> | ... | ... |
resume.bat
0 → 100644
1 | +@REM | |
2 | +@REM Copyright © 2016-2017 The Thingsboard Authors | |
3 | +@REM | |
4 | +@REM Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | +@REM you may not use this file except in compliance with the License. | |
6 | +@REM You may obtain a copy of the License at | |
7 | +@REM | |
8 | +@REM http://www.apache.org/licenses/LICENSE-2.0 | |
9 | +@REM | |
10 | +@REM Unless required by applicable law or agreed to in writing, software | |
11 | +@REM distributed under the License is distributed on an "AS IS" BASIS, | |
12 | +@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | +@REM See the License for the specific language governing permissions and | |
14 | +@REM limitations under the License. | |
15 | +@REM | |
16 | + | |
17 | +mvn clean install -rf :application | |
18 | + | ... | ... |
tools/src/main/python/mqtt-send-telemetry.py
0 → 100644
1 | +# | |
2 | +# | |
3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | +# you may not use this file except in compliance with the License. | |
5 | +# You may obtain a copy of the License at | |
6 | +# | |
7 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
8 | +# | |
9 | +# Unless required by applicable law or agreed to in writing, software | |
10 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | +# See the License for the specific language governing permissions and | |
13 | +# limitations under the License. | |
14 | +# | |
15 | + | |
16 | +import paho.mqtt.client as mqtt | |
17 | +from time import sleep | |
18 | +import random | |
19 | + | |
20 | +broker="test.mosquitto.org" | |
21 | +topic_pub='v1/devices/me/telemetry' | |
22 | + | |
23 | + | |
24 | +client = mqtt.Client() | |
25 | + | |
26 | +client.username_pw_set("qyA3gP50SpGwfwyNGyi7") | |
27 | +client.connect('127.0.0.1', 1883, 1) | |
28 | + | |
29 | +for i in range(100): | |
30 | + x = random.randrange(20, 100) | |
31 | + print x | |
32 | + msg = '{"windSpeed":"'+ str(x) + '"}' | |
33 | + client.publish(topic_pub, msg) | |
34 | + sleep(0.1) | |
35 | +#while True: | |
36 | +# val3 = random.uniform(0, 5) | |
37 | +# val4 = random.uniform(-3, 3)# | |
38 | +# | |
39 | +# msg = '{"key3": '+ str(val3) +', "key4": ' + str(val4) + '}' | |
40 | +# | |
41 | +# print('Message: ' + msg) | |
42 | +# client.publish(topic_pub, msg) | |
43 | +# | |
44 | +# sleep(0.5) | ... | ... |