Skip to content

Instantly share code, notes, and snippets.

@joohee
Created December 16, 2015 07:22
Show Gist options
  • Select an option

  • Save joohee/3b49c0403e0434d0d41e to your computer and use it in GitHub Desktop.

Select an option

Save joohee/3b49c0403e0434d0d41e to your computer and use it in GitHub Desktop.
public class PushWithOneThread {
@Value("${cloud.aws.sns.endpoint}")
private String SNS_ENDPOINT;
@Value("${cloud.aws.credentials.accessKey}")
private String ACCESS_KEY;
@Value("${cloud.aws.credentials.secretKey}")
private String SECRET_KEY;
@Inject
private SQSUtils sqsUtils;
@Inject
private PushUtils pushUtils;
public void send() {
List<PushContainer> list;
do {
list = sqsUtils.receive(Constants.SQS_RECEIVE_COUNT);
if (CollectionUtils.isEmpty(list) == false) {
final List<PushContainer> candidates = new ArrayList<>(list);
AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
AmazonSNS snsClient = new AmazonSNSAsyncClient(credentials);
snsClient.setEndpoint(SNS_ENDPOINT);
for (PushContainer pc : candidates) {
boolean result = pushUtils.sendMessage(snsClient, pc.getDevice(), pc.getMessage());
if (result) {
log.info("[SUCCESS] send message succeeded...userId: [{}], pushToken: [{}]", pc.getDevice().getUserId(), pc.getDevice().getPushToken());
} else {
log.info("[FAIL] send message failed...userId: [{}], pushToken: [{}]", pc.getDevice().getUserId(), pc.getDevice().getPushToken());
}
}
}
} while (CollectionUtils.isEmpty(list) == false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment