- 浏览: 2552840 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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 1679I am still keep notes my tech n ... -
Stop Update Here
2020-04-28 09:00 316I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 476NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 369Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 370Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 337Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 431Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 374Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 456VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 385Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 479NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 424Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 337Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 248GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 452GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 328GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 314Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 319Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 294Serverless with NodeJS and Tenc ...
相关推荐
在提供的压缩包文件中,`producer.java`可能是实现生产者消费者问题的Java代码示例。通常,这样的代码会包含两个主要类:一个代表生产者,另一个代表消费者。生产者类会有一个或多个方法用于生成数据并将其放入共享...
Producer.java
在这个例子中,"producer.java" 文件可能定义了一个生产者类,它负责生成数字并将其放入一个共享的缓冲区。另一方面,"consumer" 可能是一个消费者类,它从缓冲区取出数字进行消费。这两个线程需要通过同步机制来...
5. **代码实现**:在`Consumer-Producer.rar`中的`Consumer-Producer`文件可能包含了具体的Java代码实现,它可能包括两个类——`Producer`和`Consumer`,分别代表生产者和消费者。每个类可能有一个无限循环来持续...
在Java编程中,遇到“Exception in thread 'main' java.lang.NoClassDefFoundError”是一种常见的异常情况,这通常意味着JVM在运行时未能找到指定的类定义。此错误不同于ClassNotFoundException,后者发生在尝试加载...
The use of producer-consumer questions helps to better understand threads.
### Kafka Producer机制优化—提高发送消息可靠性 #### 一、Kafka Producer机制及问题背景 在Kafka消息系统中,消息是由Producer生产并通过Broker(消息中介节点)进行存储与转发的。Broker负责处理消息的存储,并...
阿里云LOG Java生产者Aliyun LOG Java Producer是一个易于使用且高度可配置的Java类库,专门为运行在大数据,高并发场景下的Java应用量身打造。功能特点线程安全-生产者接口暴露的所有方法都是线程安全的。初级发送-...
Photodex ProShow Producer是一款专业的视频幻灯片制作工具,它提供了丰富的模板资源和插件,使得视频制作变得快速、简便且高度可定制。它非常适合爱好制作电子相册的用户,能够满足他们多样化的制作需求。ProShow ...
2. **`Producer`和`Consumer`接口**:虽然Java标准库中没有现成的`Producer`和`Consumer`接口,但在设计模式中,我们通常定义这两个接口来表示生成数据和消耗数据的行为。实现这些接口的类将分别代表生产者和消费者...
在本文中,我们将深入探讨Laravel开发中的"Producer"概念,这是基于规则的简单类解析的一个实例。Laravel是一款流行的开源PHP框架,以其优雅的语法和强大的功能深受开发者喜爱。"Producer"可能指的是一个用于创建、...
在这个"Producer/Consumer 多线程处理文件"的主题中,我们将深入探讨Java中的生产者消费者模型,以及如何利用这一模式来高效地处理大量数据,如一秒钟处理一千多条记录。 生产者消费者模型源于操作系统理论,是解决...
《ProShow Producer 模板:打造浪漫“玫瑰婚礼”》 在数字时代,人们越来越注重个性化和创意化的表达,尤其是在婚礼这种人生中的重要时刻。ProShow Producer,一款专业的幻灯片制作软件,就为新人们提供了这样的...
主要介绍了Kafka Java Producer代码实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
ThreadIn.java 接收数据用的线程类 ThreadOut.java 发送数据用的线程类 TypeFile.java 显示文件内容的类 useScanner.java 用Scanner接收用户的输入 第8章 示例描述:本章学习多线程。 enhanceThread.java 一个...
Pentaho Kafka Producer是一款用于Pentaho Data Integration(Kettle)平台的插件,它允许用户在数据集成过程中将数据流发布到Apache Kafka消息队列。Kafka是一个分布式流处理平台,广泛应用于实时数据管道和流应用...
在工作中,理解并运用生产者消费者模型能在高并发开发中出现更少的问题,本Demo最从简而行,使用Java语言实现一个最简单的生产者消费者模型。博客地址:https://blog.csdn.net/u012552275/article/details/104730175
- **并发模式**:介绍了如Producer-Consumer、Builder、Guarded Suspension等经典并发模式,并提供了Java实现。 - **并发集合**:详述了JUC(Java Util Concurrency)库,包括ArrayList、LinkedList、HashMap等...
OID Producer是一款用于生成和管理Object Identifier(OID)的工具,主要在信息技术领域,尤其是网络协议和软件开发中使用。OID是标识数据对象的一种国际标准,它在ASN.1(抽象语法标记一世)编码规则下工作,是网络...
在Java中,我们可以创建一个Producer实例,配置相关的生产者属性(如bootstrap servers、key-value序列化类等),然后使用`send()`方法将消息发送到指定的主题。 【Kafka Consumer】 Kafka消费者则用于订阅和消费...