orpiske commented on a change in pull request #23: URL: https://github.com/apache/camel-k-examples/pull/23#discussion_r456481530
########## File path: 90-aws-kinesis-customized-event-source/extra/custom-kinesis-configuration/src/main/java/org/apache/camel/k/examples/CustomKinesisConfiguration.java ########## @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.k.examples; + +import com.amazonaws.ClientConfiguration; +import com.amazonaws.Protocol; +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.client.builder.AwsClientBuilder; +import com.amazonaws.regions.Regions; +import com.amazonaws.services.kinesis.AmazonKinesis; +import com.amazonaws.services.kinesis.AmazonKinesisClientBuilder; +import com.amazonaws.services.kinesis.model.CreateStreamResult; +import com.amazonaws.services.kinesis.model.DescribeStreamResult; +import com.amazonaws.services.kinesis.model.ResourceNotFoundException; +import org.apache.camel.component.aws.kinesis.KinesisConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CustomKinesisConfiguration extends KinesisConfiguration { + private static final Logger LOG = LoggerFactory.getLogger(CustomKinesisConfiguration.class); + + private AmazonKinesis amazonKinesis; + + static { + /* This makes the Localstack response parseable but is not necessary + * when using AWS Kinesis + */ + System.setProperty("com.amazonaws.sdk.disableCbor", "true"); + } + + private void createStream() { + CreateStreamResult result = amazonKinesis.createStream(getStreamName(), 1); + if (result.getSdkHttpMetadata().getHttpStatusCode() != 200) { + LOG.error("Failed to create the stream"); + } else { + LOG.info("Stream created successfully"); + } + } + + private AmazonKinesis buildClient() { + LOG.info("Creating a custom Kinesis client"); + + String amazonHost = System.getenv("AWS_HOST"); Review comment: It works and I think it's a bit cleaner. I updated the PR to use that. I haven't squashed so I can rollback more easily if needed, but I can do that if it's better. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
