- 浏览: 2489700 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
SNS Producer in Java in Old Project
In one Old Java Project, I need to send events to SNS in AWS. Here is how I did that>
Here is the package I need to put in dependencies.
Lib/aws-java-sdk-1.11.515.jar
Lib/aws-java-sdk-sns-1.11.515.jar
Lib/aws-java-sdk-core-1.11.515.jar
Lib/jackson-databind-2.6.6.jar
Lib/jackson-core-2.6.6.jar
Lib/jackson-annotations-2.6.6.jar
Lib/joda-time-2.10.jar
This is the major class I need
package com.sillycat.masterserver.engine.notification;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClientBuilder;
import com.amazonaws.services.sns.model.CreateTopicResult;
import com.amazonaws.services.sns.model.PublishRequest;
import com.amazonaws.util.StringUtils;
import com.google.gson.Gson;
import com.sillycat.masterserver.common.log.MasterServerLogger;
import com.sillycat.masterserver.common.log.MasterServerLogger.MMSLogLevel;
import com.sillycat.masterserver.common.utils.LoggerUtils;
public class EventBusNotificationManager {
static String ACCESS_KEY = "AWS_ACCESS_KEY";
static String SECRET_KEY = "AWS_SECRET_KEY";
static String REGION = "AWS_REGION";
static String TOPIC = "AWS_EVENTBUS_TOPIC";
static AmazonSNS client = null;
static String topicArn = null;
private static void init() {
String accessKey = System.getenv(ACCESS_KEY);
String secretKey = System.getenv(SECRET_KEY);
String region = System.getenv(REGION);
String topic = System.getenv(TOPIC);
if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)
|| StringUtils.isNullOrEmpty(region) || StringUtils.isNullOrEmpty(topic)) {
MasterServerLogger.log(MMSLogLevel.ERROR, "EventBusNotificationManager configuration error [" + "accessKey="
+ accessKey + " secretKey = " + secretKey + " region = " + region + " topic = " + topic + "] ");
return ;
}
BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
client = AmazonSNSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds))
.withRegion(region).build();
CreateTopicResult createTopicResponse = client.createTopic(topic);
topicArn = createTopicResponse.getTopicArn();
if (StringUtils.isNullOrEmpty(topicArn)) {
MasterServerLogger.log(MMSLogLevel.ERROR, "EventBusNotificationManager connection error ["
+ LoggerUtils.logClass(createTopicResponse) + "] ");
}
}
public static void sendMessage(Object msg) {
if (client == null || topicArn == null) {
init();
if(client == null) {
MasterServerLogger.log(MMSLogLevel.ERROR, "Fail to init connection with AWS SNS, give up, do not break the flow.");
return ;
}
}
String jsonMsg = convertToJSON(msg);
final PublishRequest publishRequest = new PublishRequest().withMessage(jsonMsg).withTargetArn(topicArn);
client.publish(publishRequest);
}
private static String convertToJSON(Object obj) {
return new Gson().toJson(obj);
}
}
EventBusMessage is just a POJO.
Here is the System Settings
export AWS_ACCESS_KEY=AKIxxxxxxxx
export AWS_SECRET_KEY=P3o3xxxxxxxxx
export AWS_REGION=us-west-1
export AWS_EVENTBUS_TOPIC=topicName-in-SNS
References:
https://docs.aws.amazon.com/sns/latest/dg/sns-tutorial-publish-message-to-topic.html#publish-message-to-topic-aws-java
https://stackoverflow.com/questions/31466916/sending-sms-from-java-web-app-using-aws-sns
https://www.example-code.com/java/sns_publish_send_message.asp
https://github.com/mfine/AmazonSNSExample/blob/master/AmazonSNSSender.java
https://github.com/Cs4r/SNS-producer-SQS-consumer
In one Old Java Project, I need to send events to SNS in AWS. Here is how I did that>
Here is the package I need to put in dependencies.
Lib/aws-java-sdk-1.11.515.jar
Lib/aws-java-sdk-sns-1.11.515.jar
Lib/aws-java-sdk-core-1.11.515.jar
Lib/jackson-databind-2.6.6.jar
Lib/jackson-core-2.6.6.jar
Lib/jackson-annotations-2.6.6.jar
Lib/joda-time-2.10.jar
This is the major class I need
package com.sillycat.masterserver.engine.notification;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClientBuilder;
import com.amazonaws.services.sns.model.CreateTopicResult;
import com.amazonaws.services.sns.model.PublishRequest;
import com.amazonaws.util.StringUtils;
import com.google.gson.Gson;
import com.sillycat.masterserver.common.log.MasterServerLogger;
import com.sillycat.masterserver.common.log.MasterServerLogger.MMSLogLevel;
import com.sillycat.masterserver.common.utils.LoggerUtils;
public class EventBusNotificationManager {
static String ACCESS_KEY = "AWS_ACCESS_KEY";
static String SECRET_KEY = "AWS_SECRET_KEY";
static String REGION = "AWS_REGION";
static String TOPIC = "AWS_EVENTBUS_TOPIC";
static AmazonSNS client = null;
static String topicArn = null;
private static void init() {
String accessKey = System.getenv(ACCESS_KEY);
String secretKey = System.getenv(SECRET_KEY);
String region = System.getenv(REGION);
String topic = System.getenv(TOPIC);
if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)
|| StringUtils.isNullOrEmpty(region) || StringUtils.isNullOrEmpty(topic)) {
MasterServerLogger.log(MMSLogLevel.ERROR, "EventBusNotificationManager configuration error [" + "accessKey="
+ accessKey + " secretKey = " + secretKey + " region = " + region + " topic = " + topic + "] ");
return ;
}
BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
client = AmazonSNSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds))
.withRegion(region).build();
CreateTopicResult createTopicResponse = client.createTopic(topic);
topicArn = createTopicResponse.getTopicArn();
if (StringUtils.isNullOrEmpty(topicArn)) {
MasterServerLogger.log(MMSLogLevel.ERROR, "EventBusNotificationManager connection error ["
+ LoggerUtils.logClass(createTopicResponse) + "] ");
}
}
public static void sendMessage(Object msg) {
if (client == null || topicArn == null) {
init();
if(client == null) {
MasterServerLogger.log(MMSLogLevel.ERROR, "Fail to init connection with AWS SNS, give up, do not break the flow.");
return ;
}
}
String jsonMsg = convertToJSON(msg);
final PublishRequest publishRequest = new PublishRequest().withMessage(jsonMsg).withTargetArn(topicArn);
client.publish(publishRequest);
}
private static String convertToJSON(Object obj) {
return new Gson().toJson(obj);
}
}
EventBusMessage is just a POJO.
Here is the System Settings
export AWS_ACCESS_KEY=AKIxxxxxxxx
export AWS_SECRET_KEY=P3o3xxxxxxxxx
export AWS_REGION=us-west-1
export AWS_EVENTBUS_TOPIC=topicName-in-SNS
References:
https://docs.aws.amazon.com/sns/latest/dg/sns-tutorial-publish-message-to-topic.html#publish-message-to-topic-aws-java
https://stackoverflow.com/questions/31466916/sending-sms-from-java-web-app-using-aws-sns
https://www.example-code.com/java/sns_publish_send_message.asp
https://github.com/mfine/AmazonSNSExample/blob/master/AmazonSNSSender.java
https://github.com/Cs4r/SNS-producer-SQS-consumer
发表评论
-
Update Site will come soon
2021-06-02 04:10 1614I am still keep notes my tech n ... -
Stop Update Here
2020-04-28 09:00 265I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 433NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 315Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 325Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 297Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 382Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 379Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 330Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 403VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 337Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 419NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 365Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 294Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 213GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 394GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 279GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 267Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 267Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 255Serverless with NodeJS and Tenc ...
相关推荐
用java为源代码,解决多线程编程中的经典问题:生产者消费者问题
Producer.java
java的多线程示例(生产者消费者问题)
出现Exception in threadmain java.lang.NoClassDefFoundError的各种可能情况.doc
java生产者消费者程序实现 线程,信号量互斥事件 临界资源
The use of producer-consumer questions helps to better understand threads.
Kafka Producer机制优化-提高发送消息可靠性
主要介绍了Kafka Java Producer代码实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
ThreadIn.java 接收数据用的线程类 ThreadOut.java 发送数据用的线程类 TypeFile.java 显示文件内容的类 useScanner.java 用Scanner接收用户的输入 第8章 示例描述:本章学习多线程。 enhanceThread.java 一个...
ProShow Producer模板,玫瑰婚礼,绚丽多彩的画面,替换图片即可。
在工作中,理解并运用生产者消费者模型能在高并发开发中出现更少的问题,本Demo最从简而行,使用Java语言实现一个最简单的生产者消费者模型。博客地址:https://blog.csdn.net/u012552275/article/details/104730175
Photodex ProShow Producer 模板资源和插件5G,爱好制作电子相册的朋友一定喜欢,一定能满足你的需求,资源难得。
What’s New in Java EE 7 Chapter 2 : Servlets WebServlet Servlet Filters Event Listeners Asynchronous Support Nonblocking I/O Web Fragments Security Resource Packaging Error ...
阿里云LOG Java生产者Aliyun LOG Java Producer是一个易于使用且高度可配置的Java类库,专门为运行在大数据,高并发场景下的Java应用量身打造。功能特点线程安全-生产者接口暴露的所有方法都是线程安全的。初级发送-...
Arrays in Java .............................. 44 You never need to destroy an object .................. 45 Scoping ........................................ 45 Scope of objects ...........................
生产者消费者使用java实现经典的并发或线程模式。 在分支“简化”中,代码被简化以使其更具可读性。 在“master”分支中,运行代码,可以很容易地理解真正的过程。
Laravel开发-producer 基于规则的简单类解析
Easy RealMedia Producer V1.94
acs:log:${regionName}:${projectOwnerAliUid}:project/${projectName}/logstore/${logstoreName} 设置环境变量 该示例将从环境变量中读取项目、端点、日志库和 AK 的值。 您可以在.producerrc设置它们的值,然后...
Apache Camel is a Java framework that lets you implement the standard enterprise integration patterns in a few lines of code. With a concise but sophisticated DSL you snap integration logic into your ...