当前位置: 首页>>代码示例>>Java>>正文


Java PublishRequest类代码示例

本文整理汇总了Java中com.amazonaws.services.sns.model.PublishRequest的典型用法代码示例。如果您正苦于以下问题:Java PublishRequest类的具体用法?Java PublishRequest怎么用?Java PublishRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PublishRequest类属于com.amazonaws.services.sns.model包,在下文中一共展示了PublishRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
@Override
public void run(Webhook webhook, String login, String email, String name, String subject, String content) {

    SNSWebhookApp webhookApp = (SNSWebhookApp) webhook.getWebhookApp();
    String topicArn = webhookApp.getTopicArn();
    String awsAccount = webhookApp.getAwsAccount();
    String awsSecret = webhookApp.getAwsSecret();
    String region = webhookApp.getRegion();
    AmazonSNSClient snsClient = new AmazonSNSClient(new BasicAWSCredentials(awsAccount, awsSecret));
    snsClient.setRegion(Region.getRegion(Regions.fromName(region)));

    try {
        PublishRequest publishReq = new PublishRequest()
                .withTopicArn(topicArn)
                .withMessage(getMessage(login, email, name, subject, content));
        snsClient.publish(publishReq);

    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Cannot send notification to SNS service", e);
    } finally {
        LOGGER.log(Level.INFO, "Webhook runner terminated");
    }
}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:24,代码来源:SNSWebhookRunner.java

示例2: start

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
@Test
public void start() {
  SnsListener listener = new SnsListener(client, config, clock);
  listener.circusTrainStartUp(new String[] {}, sourceCatalog, replicaCatalog);
  listener.tableReplicationStart(tableReplication, EVENT_ID);

  verify(client).publish(requestCaptor.capture());
  PublishRequest request = requestCaptor.getValue();
  assertThat(request.getSubject(), is(SUBJECT));
  assertThat(request.getTopicArn(), is("startArn"));
  assertThat(request.getMessage(),
      is("{\"protocolVersion\":\"1.0\",\"type\":\"START\",\"headers\":{\"pipeline-id\":\"0943879438\"},"
          + "\"startTime\":\"starttime\",\"eventId\":\"EVENT_ID\",\"sourceCatalog\":\"sourceCatalogName\","
          + "\"replicaCatalog\":\"replicaCatalogName\",\"sourceTable\":\"srcDb.srcTable\",\"replicaTable\":"
          + "\"replicaDb.replicaTable\"}"));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:17,代码来源:SnsListenerTest.java

示例3: success

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
@Test
public void success() {
  SnsListener listener = new SnsListener(client, config, clock);
  listener.circusTrainStartUp(new String[] {}, sourceCatalog, replicaCatalog);
  listener.tableReplicationStart(tableReplication, EVENT_ID);
  listener.partitionsToAlter(PARTITIONS_0);
  listener.partitionsToCreate(PARTITIONS_1);
  listener.copierEnd(metrics);
  listener.tableReplicationSuccess(tableReplication, EVENT_ID);

  verify(client, times(2)).publish(requestCaptor.capture());
  PublishRequest request = requestCaptor.getAllValues().get(1);
  assertThat(request.getSubject(), is(SUBJECT));
  assertThat(request.getTopicArn(), is("successArn"));
  assertThat(request.getMessage(),
      is("{\"protocolVersion\":\"1.0\",\"type\":\"SUCCESS\",\"headers\":{\"pipeline-id\":\"0943879438\"},"
          + "\"startTime\":\"starttime\",\"endTime\":\"endtime\",\"eventId\":\"EVENT_ID\",\"sourceCatalog\""
          + ":\"sourceCatalogName\",\"replicaCatalog\":\"replicaCatalogName\",\"sourceTable\":"
          + "\"srcDb.srcTable\",\"replicaTable\":\"replicaDb.replicaTable\",\"modifiedPartitions\":"
          + "[[\"2014-01-01\",\"0\"],[\"2014-01-01\",\"1\"]],\"bytesReplicated\":40}"));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:22,代码来源:SnsListenerTest.java

示例4: failure

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
@Test
public void failure() {
  SnsListener listener = new SnsListener(client, config, clock);
  listener.circusTrainStartUp(new String[] {}, sourceCatalog, replicaCatalog);
  listener.tableReplicationStart(tableReplication, EVENT_ID);
  listener.partitionsToAlter(PARTITIONS_0);
  listener.partitionsToCreate(PARTITIONS_1);
  listener.copierEnd(metrics);
  listener.tableReplicationFailure(tableReplication, EVENT_ID, ERROR);

  verify(client, times(2)).publish(requestCaptor.capture());
  PublishRequest request = requestCaptor.getValue();
  assertThat(request.getSubject(), is(SUBJECT));
  assertThat(request.getTopicArn(), is("failArn"));
  assertThat(request.getMessage(), is("{\"protocolVersion\":\"1.0\",\"type\":\"FAILURE\",\"headers\":"
      + "{\"pipeline-id\":\"0943879438\"},\"startTime\":\"starttime\",\"endTime\":\"endtime\",\"eventId\":"
      + "\"EVENT_ID\",\"sourceCatalog\":\"sourceCatalogName\",\"replicaCatalog\":\"replicaCatalogName\","
      + "\"sourceTable\":\"srcDb.srcTable\",\"replicaTable\":\"replicaDb.replicaTable\",\"modifiedPartitions\":"
      + "[[\"2014-01-01\",\"0\"],[\"2014-01-01\",\"1\"]],\"bytesReplicated\":40,\"errorMessage\":\"error message\"}"));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:21,代码来源:SnsListenerTest.java

示例5: testPublish_shouldPublishTheMessage

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
@Test
public void testPublish_shouldPublishTheMessage() {
  CreateTopicResult topicResult = sns.createTopic(new CreateTopicRequest().withName("important-topic"));
  
  PublishRequest publishReq = new PublishRequest()
      .withMessage("{\"state\":\"liquid\",\"color\":\"black\",\"waking-up\":true}")
      .withMessageStructure("json")
      .withPhoneNumber("00121212")
      .withSubject("eeffoc")
      .withTopicArn(topicResult.getTopicArn());
  
  PublishResult publishResult = sns.publish(publishReq);
  assertNotNull("verify message id",publishResult.getMessageId());
  
  Topic topic = getSnsTopics().get(topicResult.getTopicArn());
  assertEquals("verify correct message count", 1, topic.getMessages().size());
  assertEquals("verify message subject","eeffoc",topic.getMessages().get(0).getSubject());
  assertEquals("verify message body","{\"state\":\"liquid\",\"color\":\"black\",\"waking-up\":true}",topic.getMessages().get(0).getBody());
  assertEquals("verify message structure","json",topic.getMessages().get(0).getStructure());
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:21,代码来源:MockSnsTest.java

示例6: process

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
@Override
public void process(PluginContext ctx, TenantId tenantId, RuleId ruleId, RuleToPluginMsg<?> msg) throws RuleException {
    if (msg instanceof SnsTopicActionMsg) {
        SnsTopicActionPayload payload = ((SnsTopicActionMsg) msg).getPayload();
        PublishRequest publishRequest = new PublishRequest()
                .withTopicArn(payload.getTopicArn())
                .withMessage(payload.getMsgBody());
        sns.publish(publishRequest);
        if (payload.isSync()) {
            ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId,
                    BasicStatusCodeResponse.onSuccess(payload.getMsgType(), payload.getRequestId())));
        }
       return;
    }
    throw new RuleException("Unsupported message type " + msg.getClass().getName() + "!");

}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:18,代码来源:SnsMessageHandler.java

示例7: process

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
public void process(Exchange exchange) throws Exception {
    PublishRequest request = new PublishRequest();

    request.setTopicArn(getConfiguration().getTopicArn());
    request.setSubject(determineSubject(exchange));
    request.setMessageStructure(determineMessageStructure(exchange));
    request.setMessage(exchange.getIn().getBody(String.class));

    LOG.trace("Sending request [{}] from exchange [{}]...", request, exchange);
    
    PublishResult result = getEndpoint().getSNSClient().publish(request);

    LOG.trace("Received result [{}]", result);
    
    Message message = getMessageForResponse(exchange);
    message.setHeader(SnsConstants.MESSAGE_ID, result.getMessageId());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:SnsProducer.java

示例8: execute

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
@Override
public void execute(PostDownloadExecution execution) {

    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretAccessKey);

    AmazonSNS sns = snsClientBuilder.withRegion(region)
            .withCredentials(new AWSStaticCredentialsProvider(credentials)).build();

    LOGGER.debug("SNS: Topic Arn               : {}", arn);
    LOGGER.debug("SNS: Topic Region            : {}", region);
    LOGGER.debug("SNS: Topic Access Key        : {}", accessKey);
    LOGGER.debug("SNS: Topic Secret Access Key : {}", secretAccessKey);

    PublishRequest request = new PublishRequest();
    request.setTopicArn(arn);
    request.setMessageStructure("json");
    request.setMessage(formatJsonMessage(execution.fileName));
    request.setSubject("A new file has been downloaded");

    LOGGER.info("Publishing message to SNS");
    PublishResult result = sns.publish(request);
    LOGGER.info("Publish successful!");
    LOGGER.debug("{}", result.getMessageId());
}
 
开发者ID:linuxserver,项目名称:davos,代码行数:25,代码来源:SNSNotifyAction.java

示例9: notify

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
public void notify(String topicId, String title, String message) {

		try {
			if (topicId == null)
				Utils.warn("Unable to send internal notification [%s][%s]: no SNS topic id.", //
						title, message);
			else
				snsClient.publish(new PublishRequest()//
						.withTopicArn(topicId)//
						.withSubject(title)//
						.withMessage(message));

		} catch (Throwable ignore) {
			ignore.printStackTrace();
		}
	}
 
开发者ID:spacedog-io,项目名称:spacedog-server,代码行数:17,代码来源:Internals.java

示例10: main

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

		final AmazonSNSClient client = Region.getRegion(Regions.EU_CENTRAL_1).createClient(AmazonSNSClient.class, null,
				null);
		CreateTopicResult createTopic = client.createTopic("facilities");
		createTopic.getTopicArn();
		SubscribeResult subscribe = client.subscribe(createTopic.getTopicArn(), "email", "[email protected]");
		final PublishRequest publishRequest = new PublishRequest(createTopic.getTopicArn(), "Test message");
		client.publish(publishRequest);
	}
 
开发者ID:highsource,项目名称:aufzugswaechter,代码行数:11,代码来源:HelloWorldSNS.java

示例11: shouldPublish_withSubjectAndMessage

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
@Test
public void shouldPublish_withSubjectAndMessage() {
    // Given
    final String subject = randomString();
    final String message = randomString();

    // When
    snsTopicResource.publish(subject, message);

    // Then
    final ArgumentCaptor<PublishRequest> captor = ArgumentCaptor.forClass(PublishRequest.class);
    verify(mockAmazonSnsClient).publish(captor.capture());
    final PublishRequest publishRequest = captor.getValue();
    assertEquals(topicArn, publishRequest.getTopicArn());
    assertEquals(subject, publishRequest.getSubject());
    assertEquals(message, publishRequest.getMessage());
    assertEquals(subject, publishRequest.getMessageAttributes().get("subject").getStringValue());
    assertEquals("String", publishRequest.getMessageAttributes().get("subject").getDataType());
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:20,代码来源:SnsTopicResourceTest.java

示例12: shouldThrowException_onAmazonClientExceptionFromPublish

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
@Test
public void shouldThrowException_onAmazonClientExceptionFromPublish() {
    // Given
    final String subject = randomString();
    final String message = randomString();
    when(mockAmazonSnsClient.publish(any(PublishRequest.class))).thenThrow(AmazonClientException.class);

    // When
    AmazonClientException thrownException = null;
    try {
        snsTopicResource.publish(subject, message);
    } catch (final AmazonClientException e) {
        thrownException = e;
    }

    // Then
    assertNotNull(thrownException);
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:19,代码来源:SnsTopicResourceTest.java

示例13: sendPushMessage

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
public PublishResult sendPushMessage(AmazonSNS snsClient, PushPlatform platform, String targetArn, String message,
		Map<String, MessageAttributeValue> messageAttributes) throws IOException {
	Map<String, String> messageMap = new HashMap<String, String>();
	messageMap.put(platform.name(), message);
	message = ServerUtil.asJson(messageMap);

    PublishRequest publishRequest = new PublishRequest();
	publishRequest.setMessageStructure("json");
	
	if (messageAttributes != null) {
		publishRequest.setMessageAttributes(messageAttributes);
	}

	publishRequest.setTargetArn(targetArn);
	publishRequest.setMessage(message);

	PublishResult publishResult = snsClient.publish(publishRequest);

	return publishResult;
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:21,代码来源:PushSnsService.java

示例14: testActions

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
@Test
@Ignore
public void testActions() {

    // setAttribtues
    String userData = UUID.randomUUID().toString();
    endpoint.setAttributes(new SetEndpointAttributesRequest()
            .addAttributesEntry("CustomUserData", userData)
            );
    refreshEndpoint();
    Assert.assertEquals(userData, endpoint.getAttributes().get("CustomUserData"));

    // publish
    endpoint.publish(new PublishRequest()
            .withSubject("subject")
            .withMessage("message")
            );
}
 
开发者ID:awslabs,项目名称:aws-sdk-java-resources,代码行数:19,代码来源:PlatformEndpointIntegrationTest.java

示例15: send_validTextMessage_usesTopicChannel

import com.amazonaws.services.sns.model.PublishRequest; //导入依赖的package包/类
@Test
public void send_validTextMessage_usesTopicChannel() throws Exception {
    // Arrange
    AmazonSNS amazonSns = mock(AmazonSNS.class);
    NotificationMessagingTemplate notificationMessagingTemplate = new NotificationMessagingTemplate(amazonSns);
    String physicalTopicName = "arn:aws:sns:eu-west:123456789012:test";
    when(amazonSns.listTopics(new ListTopicsRequest(null))).thenReturn(new ListTopicsResult().withTopics(new Topic().withTopicArn(physicalTopicName)));
    notificationMessagingTemplate.setDefaultDestinationName(physicalTopicName);

    // Act
    notificationMessagingTemplate.send(MessageBuilder.withPayload("Message content").build());

    // Assert
    verify(amazonSns).publish(new PublishRequest(physicalTopicName,
            "Message content", null).withMessageAttributes(isNotNull()));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:17,代码来源:NotificationMessagingTemplateTest.java


注:本文中的com.amazonaws.services.sns.model.PublishRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。