Skip to main content

Posts

Showing posts from March, 2020

Run first Kafka Produce-Consumer Demo - Inside Kafka (3)

Firstly, go through the first part of producer sending the message The ProduceRecord has 6 main properties: a. topic: the topic the record will be tiered with. b. partition: the partition which the record will be sent to c. timestamp: the timestamp the record is marked. null to use System.currentTimeMills() d. key: e: value: f: header: let's the check the main core line of send the message from KafkaProducer.doSend: RecordAccumulator.RecordAppendResult result = accumulator .append(tp , timestamp , serializedKey , serializedValue , headers , interceptCallback , remainingWaitMs) ; all other lines are used to collect data for this method: tp:  TopicPartition  the destination where the message will go timestamp: the created time of record serializedKey: the bytes of message key value. serializedValue: the bytes of message body value. headers: interceptCallback: remainingWaitMs:

How to create spring boot rest app and authenticate with cognito of AWS

Recently, just put all staff done to create a fundamental work to migrate the existing system to aws beanstalk. The main reason to use beanstalk is because that the current system used spring+java. Beanstalk will be make it easy to handle the serverless environment to save the company cost. 1. Write the basic spring boot rest application, I created 2 controller, one for authenticate to fetch te token and one DemoController to support general resource request using Bearer Token of Cognito. DemoController: 2.Configure to set the public access to /auth and secured access to /demo The SecurityConfig.java above also defined the JWTAuthenticateEntryPoint to handle the validation error case and JwtAuthenticationFilter to do the validation based on cognito Bearer token. JWTAuthenticateEntryPoint: JwtAuthenticationFilter: The line 18 set the credential back to requestContext as the global context which is used by DemoController above. 3. Start the spring boot server, and run