com.amazonaws.services.kinesis.AmazonKinesisAsync Java Examples

The following examples show how to use com.amazonaws.services.kinesis.AmazonKinesisAsync. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KinesisMessageChannelBinder.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 6 votes vote down vote up
public KinesisMessageChannelBinder(KinesisBinderConfigurationProperties configurationProperties,
		KinesisStreamProvisioner provisioningProvider, AmazonKinesisAsync amazonKinesis,
		AWSCredentialsProvider awsCredentialsProvider,
		@Nullable AmazonDynamoDB dynamoDBClient,
		@Nullable AmazonDynamoDBStreams dynamoDBStreams,
		@Nullable AmazonCloudWatch cloudWatchClient) {

	super(headersToMap(configurationProperties), provisioningProvider);
	Assert.notNull(amazonKinesis, "'amazonKinesis' must not be null");
	Assert.notNull(awsCredentialsProvider, "'awsCredentialsProvider' must not be null");
	this.configurationProperties = configurationProperties;
	this.amazonKinesis = amazonKinesis;
	this.cloudWatchClient = cloudWatchClient;
	this.dynamoDBClient = dynamoDBClient;
	this.awsCredentialsProvider = awsCredentialsProvider;

	if (dynamoDBStreams != null) {
		this.dynamoDBStreamsAdapter = new AmazonDynamoDBStreamsAdapterClient(dynamoDBStreams);
	}
	else {
		this.dynamoDBStreamsAdapter = null;
	}
}
 
Example #2
Source File: CloudStreamKinesisToWebfluxApplicationTests.java    From spring-cloud-stream-samples with Apache License 2.0 6 votes vote down vote up
@Bean
public AmazonKinesisAsync amazonKinesis() {
	// See https://github.com/mhart/kinesalite#cbor-protocol-issues-with-the-java-sdk
	System.setProperty(SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY, "true");

	return AmazonKinesisAsyncClientBuilder.standard()
			.withClientConfiguration(
					new ClientConfiguration()
							.withMaxErrorRetry(0)
							.withConnectionTimeout(1000))
			.withEndpointConfiguration(
					new AwsClientBuilder.EndpointConfiguration("http://localhost:" + DEFAULT_KINESALITE_PORT,
							Regions.DEFAULT_REGION.getName()))
			.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("", "")))
			.build();
}
 
Example #3
Source File: AmazonAsyncDockerClientsHolder.java    From spring-localstack with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonKinesisAsync amazonKinesis() {
    return decorateWithConfigsAndBuild(
        AmazonKinesisAsyncClientBuilder.standard(),
        LocalstackDocker::getEndpointKinesis
    );
}
 
Example #4
Source File: KinesisBinderConfiguration.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public AmazonKinesisAsync amazonKinesis() {
	return AmazonKinesisAsyncClientBuilder.standard()
			.withCredentials(this.awsCredentialsProvider)
			.withRegion(this.region)
			.build();
}
 
Example #5
Source File: KinesisTestBinder.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 5 votes vote down vote up
TestKinesisMessageChannelBinder(AmazonKinesisAsync amazonKinesis,
		AmazonDynamoDBAsync dynamoDbClient,
		KinesisBinderConfigurationProperties kinesisBinderConfigurationProperties,
		KinesisStreamProvisioner provisioningProvider) {

	super(kinesisBinderConfigurationProperties, provisioningProvider, amazonKinesis,
			new AWSStaticCredentialsProvider(new BasicAWSCredentials("", "")), dynamoDbClient, null, null);
}
 
Example #6
Source File: ExtendedDockerTestUtils.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 5 votes vote down vote up
public static AmazonKinesisAsync getClientKinesisAsync() {
	AmazonKinesisAsyncClientBuilder amazonKinesisAsyncClientBuilder =
			AmazonKinesisAsyncClientBuilder.standard()
					.withEndpointConfiguration(
							createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointKinesis));
	return applyConfigurationAndBuild(amazonKinesisAsyncClientBuilder);
}
 
Example #7
Source File: KinesisSender.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
AmazonKinesisAsync get() {
  if (asyncClient == null) {
    synchronized (this) {
      if (asyncClient != null) return asyncClient;
      AmazonKinesisAsyncClientBuilder builder = AmazonKinesisAsyncClientBuilder.standard()
          .withCredentials(credentialsProvider)
          .withEndpointConfiguration(endpointConfiguration);
      if (region != null) builder.withRegion(region);
      asyncClient = builder.build();
    }
  }
  return asyncClient;
}
 
Example #8
Source File: KinesisBinderConfiguration.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 4 votes vote down vote up
@Bean
public KinesisStreamProvisioner provisioningProvider(AmazonKinesisAsync amazonKinesis) {
	return new KinesisStreamProvisioner(amazonKinesis, this.configurationProperties);
}
 
Example #9
Source File: KinesisMessageChannelBinder.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 4 votes vote down vote up
public AmazonKinesisAsync getAmazonKinesis() {
	return this.amazonKinesis;
}
 
Example #10
Source File: KinesisTestBinder.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 4 votes vote down vote up
public KinesisTestBinder(AmazonKinesisAsync amazonKinesis, AmazonDynamoDBAsync dynamoDbClient,
		KinesisBinderConfigurationProperties kinesisBinderConfigurationProperties) {

	this.applicationContext = new AnnotationConfigApplicationContext(Config.class);

	this.amazonKinesis = amazonKinesis;

	KinesisStreamProvisioner provisioningProvider = new KinesisStreamProvisioner(
			amazonKinesis, kinesisBinderConfigurationProperties);

	KinesisMessageChannelBinder binder = new TestKinesisMessageChannelBinder(
			amazonKinesis, dynamoDbClient, kinesisBinderConfigurationProperties,
			provisioningProvider);

	binder.setApplicationContext(this.applicationContext);

	setBinder(binder);
}
 
Example #11
Source File: KinesisBinderTests.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testProducerErrorChannel() throws Exception {
	KinesisTestBinder binder = getBinder();

	final RuntimeException putRecordException = new RuntimeException(
			"putRecordRequestEx");
	final AtomicReference<Object> sent = new AtomicReference<>();
	AmazonKinesisAsync amazonKinesisMock = mock(AmazonKinesisAsync.class);
	BDDMockito
			.given(amazonKinesisMock.putRecordAsync(any(PutRecordRequest.class),
					any(AsyncHandler.class)))
			.willAnswer((Answer<Future<PutRecordResult>>) (invocation) -> {
				PutRecordRequest request = invocation.getArgument(0);
				sent.set(request.getData());
				AsyncHandler<?, ?> handler = invocation.getArgument(1);
				handler.onError(putRecordException);
				return mock(Future.class);
			});

	new DirectFieldAccessor(binder.getBinder()).setPropertyValue("amazonKinesis",
			amazonKinesisMock);

	ExtendedProducerProperties<KinesisProducerProperties> producerProps = createProducerProperties();
	producerProps.setErrorChannelEnabled(true);
	DirectChannel moduleOutputChannel = createBindableChannel("output",
			createProducerBindingProperties(producerProps));
	Binding<MessageChannel> producerBinding = binder.bindProducer("ec.0",
			moduleOutputChannel, producerProps);

	ApplicationContext applicationContext = TestUtils.getPropertyValue(
			binder.getBinder(), "applicationContext", ApplicationContext.class);
	SubscribableChannel ec = applicationContext.getBean("ec.0.errors",
			SubscribableChannel.class);
	final AtomicReference<Message<?>> errorMessage = new AtomicReference<>();
	final CountDownLatch latch = new CountDownLatch(1);
	ec.subscribe((message) -> {
		errorMessage.set(message);
		latch.countDown();
	});

	String messagePayload = "oops";
	moduleOutputChannel.send(new GenericMessage<>(messagePayload.getBytes()));

	assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
	assertThat(errorMessage.get()).isInstanceOf(ErrorMessage.class);
	assertThat(errorMessage.get().getPayload())
			.isInstanceOf(AwsRequestFailureException.class);
	AwsRequestFailureException exception = (AwsRequestFailureException) errorMessage
			.get().getPayload();
	assertThat(exception.getCause()).isSameAs(putRecordException);
	assertThat(((PutRecordRequest) exception.getRequest()).getData())
			.isSameAs(sent.get());
	producerBinding.unbind();
}
 
Example #12
Source File: KinesisBinderProcessorTests.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 4 votes vote down vote up
@Bean(destroyMethod = "")
public AmazonKinesisAsync amazonKinesis() {
	return AMAZON_KINESIS;
}
 
Example #13
Source File: KinesisSender.java    From zipkin-aws with Apache License 2.0 4 votes vote down vote up
@Override public synchronized void close() {
  if (closeCalled) return;
  AmazonKinesisAsync asyncClient = this.asyncClient;
  if (asyncClient != null) asyncClient.shutdown();
  closeCalled = true;
}