ããã«ã¡ã¯ããããã¯ãéçºé¨ã®ä¸ç°ã§ãã
ä»åã¯ãã¤ãã³ãé£æºåºç¤ã®æè¡é¸å®ã«ããã¦ãååã®EventBridgeç·¨ã«å¼ãç¶ããMessageBrokerã®åè£ã¨ãã¦æããAmazon Managed Streaming for Apache Kafkaï¼ä»¥éãMSKã¨è¨è¿°ï¼ããã³Axon Frameworkï¼ä»¥éãAxonã¨è¨è¿°ï¼ã«ã¤ãã¦ãå®éã«ããã£ã¦ã¿ã¦æ°ã¥ããç¹ããç´¹ä»ãã¾ãã
- ã¤ãã³ãé£æºåºç¤ã®æè¡é¸å®ããã話ããèæ¯ã»èª²é¡ç·¨ã
- ã¤ãã³ãé£æºåºç¤ã®æè¡é¸å®ããã話ããEventBridgeããã£ã¦ã¿ãç·¨ã
- ã¤ãã³ãé£æºåºç¤ã®æè¡é¸å®ããã話ããAxon + MSKããã£ã¦ã¿ãç·¨ããâä»åã¯ãã®è©±
- ã¤ãã³ãé£æºåºç¤ã®æè¡é¸å®ããã話ããæ¯è¼ã»çµè«ç·¨ã
æ¬è¨äºã®æ¦è¦
ååè¨äºã§ã¯EventBridgeãããã£ã¦ã¿ã¦æ°ã¥ãããã¨ãè¨è¼ãã¾ããããä»åã¯MSKã«ã¤ãã¦ãåæ§ã«ãã¤ãã³ãé£æºåºç¤ã®MessageBrokerã®åè£ã¨ãã¦æããçç±ãæ§ææ¡ã¨ãããã£ã¦ã¿ã¦å¾ãæ°ã¥ããã¾ã¨ãã¾ãã
詳細ã¯å¾è¿°ãã¾ãããMSKã¯Axonã¨çµã¿åããã¦å©ç¨ãããã¨ãåæã¨ãã¦åè£ã«æããã®ã§ãMSKãKafkaãã®ãã®ã¨ããããããAxonã®ä½¿ãåæã«é¢ããè¨è¿°ãå¤ããªã£ã¦ããç¹ã¯ãäºæ¿ãã ããã
Axonï¼MSKãåè£ã«ãããçç±
ãã£ããã¯ãæç¬å 宣ããã®ä»¥ä¸ã®çºè¡¨ãè³æãè¦ããã¨ã§ãã
- å®è·µPub/Subãã¤ã¯ããµã¼ãã¹
- ã¤ãã³ãé§åã¢ã¼ããã¯ãã£å°å ¥ã®æå¼ãã¨å ±éã®è½ã¨ãç©´
ãããã®è³æã¯ãAxonãç¥ããã£ããã«ãªã£ãã ãã§ãªããæåã®è¨äºã§è¨è¼ããã¤ãã³ãé£æºåºç¤ã®è¦ä»¶æ´çã«ããã¦ãé常ã«åèã«ãªãã¾ããã
Axon
Axonã¯ãDDDããã³CQRS/ESãå®ç¾ãããã¬ã¼ã ã¯ã¼ã¯ã§ãããååè¨äºã§ãè¨è¼ãããPublisherã®Transactional outboxãã¿ã¼ã³ã®å®è£ ãã¯ãããSubscriberå´ã§ã®ãªãã©ã¤ãDLQãåçãªã©ãã¤ãã³ãé£æºã«ããã¦å¿ è¦ã¨ãããæ©è½ãæä¾ãã¦ãããã®ã§ãCQRS/ESã¯è¡ããã«ãã¤ã¯ããµã¼ãã¹éã®ã¤ãã³ãé£æºãè¡ãã ãã®å ´åã§ãå©ç¨ã§ãã¾ãã
SpringBootã¨ã®çµ±åãå¯è½ãªãããAutoConfigurationã«ããå°ãªãè¨å®é ç®ã§ç°¡åã«å°å ¥ãããã¨ãã§ãã¾ãããConfigurationã¯ã©ã¹ãå®è£ ãããã¨ã§é¨åçã«ã«ã¹ã¿ãã¤ãºãããã¨ãå¯è½ã§ãã
ã¾ããAxonãKafkaã¨çµ±åããããã®extensionãæä¾ããã¦ããã®ã§ãæ½è±¡åãããã¤ã³ã¿ã¼ãã§ã¼ã¹ã§ã¢ããªã±ã¼ã·ã§ã³ããã»ã¨ãã©æèãããã¨ãªãKafkaã¨ã®ã¤ãã³ãéåä¿¡ããããã¨ãã§ãã¾ãã
MSKï¼Apache Kafkaï¼
Kafkaãåä½ã§åè£ã«æããã¨ããããã¯ãAxonã¨çµ±åããã¦ããMessageBrokerã¨ãã¦Kafkaãé¸ãã ã¨ããå½¢ã§ãã
Kafkaèªä½ããã¡ãã»ã¼ã¸ã³ã°åºç¤ã¨ãã¦åºãå©ç¨ããã¦ãããã®ãªã®ã§ãä¿¡é ¼æ§ãã¹ã±ã¼ã©ããªãã£ãæå¾ ã§ããKafka Connectã«ããä»ãªã½ã¼ã¹é£æºãã¯ãããæ¡å¼µæ§ãããã¾ãã
ã¨ã¯ãããKafkaã®ã¯ã©ã¹ã¿ã¼ãæ§ç¯ã»éç¨ããã«ã¯ãKafkaã«ã¤ãã¦ä¸å®ã®ç¥èãå¿ è¦ãªç¹ã¯æ°ãããã§ãã AWSã®å ´åãKafkaã®ãã«ããã¼ã¸ããµã¼ãã¹ã¨ãã¦MSKãããã®ã§ããããå©ç¨ãããã¨ã§ãæ§ç¯ã»éç¨ã®è² æ ã軽æ¸ãããã¨ããã§ãã
MSKã®å ´åãAWSã®ä»ãµã¼ãã¹ã§ããLambdaãFirehoseãEventBridgePipesçã¨ã®çµ±åãå¯è½ãªç¹ãã¡ãªããã«ãªãã¾ãã
æ§ææ¡
Axonã¨MSKãå©ç¨ããæ§æã¨ãã¦ä»¥ä¸ã®ãããªãã®ãèãã¾ããã
ãã¨ãã¨Kotlin/SpringBootã§å®è£ ããã¦ãããã¤ã¯ããµã¼ãã¹ã«ã¤ãã¦ã¯ãAxonãå°å ¥ããã ãã§ç´æ¥Kafkaã¨ã¤ãã³ãéåä¿¡ãè¡ããã¨ãã§ãã¾ãã
PHPã§ä½ãããã¢ããªã¹ã«ã¤ãã¦ã¯ãå¾è¿°ãã¾ãã
æ¤è¨¼å 容
è¦ä»¶ãå®ç¾ããããã®Axonã§ã®å®è£ æ¹æ³ãç解ãããã¨ã主ãªç®çã¨ããå®éã«Axonãå©ç¨ãããµã³ãã«ã¢ããªã±ã¼ã·ã§ã³ãå®è£ ãã¦ã¿ãªããç解ãé²ãã¾ããã
確èªããå 容ã®æ¦è¦ã¨ãã¦ã¯ä»¥ä¸ã«ãªãã¾ãã
- åºæ¬çãªåä½ã®ç¢ºèª
- Kafkaã¸ã®ã¤ãã³ãéä¿¡
- ã¤ãã³ãã®åï¼ã¯ã©ã¹ï¼ã¨éä¿¡å Kafkaãããã¯ã®ãããã³ã°
- è¤æ°ãã¼ãããã®éä¿¡æã®æå確èª
- Kafkaããã®ã¤ãã³ãåä¿¡
- KafkaMessageSourceã®æ¯è¼
- SubscribableKafkaMessageSource
- StreamableKafkaMessageSource
- è¤æ°ãã¼ãã§ã®è² è·åæ£æ¹æ³
- KafkaMessageSourceã®æ¯è¼
- Kafkaã¸ã®ã¤ãã³ãéä¿¡
- é害æã®èª¿æ»ã»ãªã«ããªæ¹æ³
- Producer
- event-processor-modeã¨confirmation-modeã®è¨å®ãã¨ã®æå確èª
- acksè¨å®ãã¨ã®æå確èª
- Consumer
- EventHandlerã¡ã½ããå ã§ä¾å¤ã¹ãã¼æã®æå確èªã¨ã«ã¹ã¿ãã¤ãºæ¹æ³ç¢ºèª
- DLQã®ç»é²ããã³ãªãã©ã¤ãã®æ¹æ³ã®ç¢ºèª
- Replayæ¹æ³ã®ç¢ºèª
- Producer
- gaugeã§ã®çµåãã¹ãæ¹æ³
- APIåä½ã®çµåãã¹ãç¸å½ã®ãã¹ãããKafkaã®ã¤ãã³ãéåä¿¡ãå«ãã¦è¡ãæ¹æ³
ãã¼ã«ã«ç°å¢ã§ã¯ãdocker composeã§Kafkaããã³Producer/Consumerã¨ãªãã¢ããªã±ã¼ã·ã§ã³ãèµ·åããåä½ç¢ºèªãè¡ãã¾ããã
AWSä¸ã§ã¯ãMSKã¯ã©ã¹ã¿ã¼ãããã¸ã¡ã³ãã³ã³ã½ã¼ã«ããä½æããProducer/Consumerã¨ãªãã¢ããªã±ã¼ã·ã§ã³ãECSã§èµ·åãã¦ãMSKã«æ¥ç¶ãã¾ããã
Axonã§ã¤ãã³ããéåä¿¡ããã¨ãã®Kotlinã®ã³ã¼ãã®ã¤ã¡ã¼ã¸ã¯ä»¥ä¸ã®ãããªãã®ã§ãã
Producerå´
suspend fun handleEvent(event: DomainEvent) { when (event) { is ConveniencePaymentCompleted -> eventGateway.publish(event.toSharedEvent()) } }
Consumerå´
@EventHandler fun on(event: ConveniencePaymentCompleted) { if (event.paymentSubjectId == facilityStoreSubjectId) { ConvenienceUseCase.CompleteInput( paymentId = event.paymentId, completedAt = event.paymentDate, processedAt = event.processDate, ).let { input -> convenienceUseCase.complete(input).getOrElse { it.handle() } } } }
大å¤ã ã£ãã®ã¯Axonã«é¢ããæ å ±éãã¾ã å°ãªããã¨ã§ãããç¹ã«æ¥æ¬èªã®æ å ±ã¯å°ãªããè±èªãå¾æã§ãªãç§ã¯å ¬å¼ããã¥ã¡ã³ãã翻訳ããªããèªããããªãç¶æ³ã§ããã ChatGPTãªã©ã«èãã¦ã¿ã¦ããå ¬å¼ããã¥ã¡ã³ãã§è¦ããã¨ãããæ å ±ä»¥ä¸ã¯åºã¦ããªããã¨ãå¤ãã£ãå°è±¡ã§ããï¼ããã³ãããè¯ããªãã£ãã ãããããã¾ãããï¼
çµå±åèã«ãªã£ãã®ã¯ã以ä¸ã®ï¼ç¹ã§ããã
- Axonå ¬å¼ããã¥ã¡ã³ã
- extension-kafkaãªãã¸ããªã®ãµã³ãã«ã³ã¼ã
- æç¬ããã®ãµã³ãã«ã³ã¼ã
ã¡ãªã¿ã«ãIntellijãJavaã®ã³ã¼ããã³ããããã¨èªåã§Kotlinã«å¤æãã¦ãããã®ã¯å°å³ã«ä¾¿å©ã§ããã
ã¾ãããã¯ãKafkaèªä½ãç解ãããã¨ãé¿ãããã¨ã¯ã§ãã¾ããã§ããã ã³ãã¢ã³ã§ã¯ãªã©ã¤ãªã¼å¦ç¿ãã©ãããã©ã¼ã ãå°å ¥ããã¦ããã®ã§ãKafka: The Definitive Guideãªã©ãã¾ã æ¥æ¬èªçãåºã¦ããªãæ¸ç±ããã©ã¦ã¶ã§ç¿»è¨³ããªããèªããã¨ãã§ããã®ã¯ãããããã£ãã§ãã
æ°ã«ãªããã¨
MessageBrokerï¼MSKï¼
ã¯ã©ã¹ã¿ã¼æ§ç¯
ãã¯ãKafkaã¯ã©ã¹ã¿ã¼ã®æ§ç¯ã»éç¨ã®é£æ度ããã£ã¨ãæ°ã«ãªãã¨ããã§ãã
AWSã®ããã¸ã¡ã³ãã³ã³ã½ã¼ã«ããMSKã¯ã©ã¹ã¿ã¼ãæ§ç¯ãã¦ã¿ãã¨ãããè¨å®é ç®ã¯ããã»ã©å¤ãã¯ãªããé£ãããªãå°è±¡ã§ããã Kafkaã®ãã¼ã¸ã§ã³ãBrokerå°æ°ãèªè¨¼æ¹æ³ã¨ãVPCè¨å®ãéä¿¡ã»ä¿åã®æå·åãããã§ãã Kafkaã¯ã©ã¹ã¿ã¼èªä½ã®è¨å®é ç®ã¯å¤ãããã¾ãããMSKç¨ã®ããã©ã«ãè¨å®ä¸å¼ãç¨æããã¦ããã®ã§ãå°ãªãã¨ãæåã¯ããããã®ã¾ã¾ä½¿ãã®ãç¡é£ããã§ãã
ãã ãä½æãã¦ããèµ·åãã¦ã¢ã¯ãã£ããªç¶æ ã«ãªãã¾ã§ã«ã¯ããªãæéãããã£ãã®ã§ãå¾ ã£ã¦ããéã¯ãã¾ããããä¸å®ã«ãªãã¾ãããã ããã30åãããããã£ããã¨æãã¾ãã
ãã¼ã¸ã§ã³ã¢ãã
Kafkaããã³MSKã®ãã¼ã¸ã§ã³ã¢ããé »åº¦ã®å¾åãè¦ãã¨ãããã1ã2å¹´ãã¨ã«æ°ãã¼ã¸ã§ã³ããªãªã¼ã¹ããã¦ããããã§ãã
äºææ§ããªã·ã¼ã«ã¤ãã¦ã¯Kafkaã®ããã¥ã¡ã³ãå ã§ãè¨åã¯ããã¦ãã¾ãããAxonããã³Kafkaã¯ã©ã¤ã¢ã³ãã®ã©ã¤ãã©ãªã¯ææ°ã«ä¿ã£ã¦ãããæ¹ãããããã§ãã ã³ãã¢ã³ã§ã¯Dependabotã®éç¨ãå®çåãã¦ãã¦ããã®ã§ãã¯ã©ã¤ã¢ã³ãå´ã®ãã¼ã¸ã§ã³ã¢ããã«ã¤ãã¦ã¯æ¯è¼çå®å¿ã§ãããã§ãã
Kafkaã¯ã©ã¹ã¿ã¼å´ã®ãã¼ã¸ã§ã³ã¢ããã¯ãããã¸ã¡ã³ãã³ã³ã½ã¼ã«ããç¡åæ¢ã§å®¹æã«å®è¡ã§ãããã§ãã ãã ãããã¼ãªã³ã°ã¢ãããã¼ãã¨ãªããããªãæéã¯ãããããã§ãããã¼ã¸ã§ã³ã¢ããã§ã¯ãªãã§ãããã¯ã©ã¹ã¿ã¼ã®è¨å®å¤æ´ãè¡ãªã£ãéããä½ææã¨åæ§ã«30åãããããã£ãã®ã§ãæåããã¾ã§å¾ ã¤æéã¯ã¡ãã£ã¨ç²¾ç¥çã«ã¤ããã£ãã§ãã
ã¾ãããã¼ã¸ã§ã³ãã¦ã³ã¯ã§ããªããããªã®ã§ãäºåã«æ°ãã¼ã¸ã§ã³ã®ã¯ã©ã¹ã¿ã¼ãå¥éç«ã¦ã¦æ¤è¨¼ãããªã©ãæ éã«è¡ãå¿ è¦ãããããã§ãã
æé
MSKã¯ãEventBridgeã¨ã¯ç°ãªããEC2çã®ããã«ç¨¼åæéã«å¿ãã¦èª²éãããã¢ãã«ã«ãªã£ã¦ãã¾ãã ãããã¸ã§ã³ãã¿ã¤ãã ãã§ãªããµã¼ãã¬ã¹ã¿ã¤ãã§ã®èµ·åãå¯è½ã§ãããæéåä½ã§æéãçºçããç¹ã¯åãã§ãã
æ¬çªç¨¼åæ³å®ã§ãkraftã¢ã¼ããé層åã¹ãã¬ã¼ã¸ã使ç¨ã§ããã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãã§ã®æå°æ§æã ã¨ãã¹ãã¬ã¼ã¸ãå«ãæããã700USDåå¾ãããè¨ç®ã«ãªãã¾ãã ã¡ãªã¿ã«ããµã¼ãã¬ã¹ã¿ã¤ãã ã¨ãä¸è¨ã®ãããã¸ã§ã³ãã¿ã¤ãã®æå°æ§æãããé«ããªã£ãããã§ããã¼ãã£ã·ã§ã³ä½æãã¨ã«è¿½å æéãçºçããã®ã§ãé¸æãã¾ããã§ããã
æ¤è¨¼ç°å¢ãã¹ãã¼ã¸ã³ã°ç°å¢ã«ãåæ§ã®ã¯ã©ã¹ã¿ã¼ãæ§ç¯ããã¨ãªãã¨ã2åã3åã®ã³ã¹ããããããã¨ã«ãªãã¾ãã
EventBridgeï¼API Destinations使ç¨ã®å ´åï¼ããã¤ãã³ã100ä¸ä»¶ããã1.24USDã§ããã®ã¨æ¯ã¹ãã¨ãããªãé«ãã¤ãã¾ããç¹ã«å°å ¥åæã¯å©ç¨ãã¾ã å°ãªãã®ã§ãæéå·®ãé¡èã§ãã
å°æ¥æ§
AWSã®ããã¥ã¡ã³ãçãè¦ãéããMSKã¯ã主ã«ãªã³ãã¬ããã®ç§»è¡ç¨éããKafka Connectçã®å¨è¾ºãã¼ã«ãå©ç¨ãããã±ã¼ã¹ã§ç´¹ä»ããã¦ããããã以å¤ã§ã¯ããã»ã©æ¨å¥¨ã¯ããã¦ããªãããã§ãã ãã®ãããä»å¾ã®æ©è½æ¹åã®ãã¼ã¹ããµã¼ãã¹ç¶ç¶ã«ã¤ãã¦ã¯ãè¥å¹²ã®ä¸å®ãããã®ãæ£ç´ãªã¨ããã§ãã
ã¢ããªã±ã¼ã·ã§ã³å®è£
Axonï¼kafka-extensionå«ãï¼ã®è¨å®ã®æ¤è¨
Axonã®Kafkaé£æºã«é¢ããè¨å®å 容ãç解ããã¦ã¼ã¹ã±ã¼ã¹ã«å¿ãã¦é¸æããå¿ è¦ãããã¾ãã
Publisherï¼Kafkaã®ç¨èªã§ã¯Producerï¼å´
AxonããKafkaã«ã¤ãã³ãéä¿¡ããããã§ã®ä¸»ãªè¨å®ããevent-processor-modeã¨confirmation-modeã§ãã
詳細ã¯Axonã®ããã¥ã¡ã³ããåç §ããã ãã®ãããã¨æãã¾ãããç°¡åã«è¨ã£ã¦ãã¾ãã¨ä»¥ä¸ã®ãããªãã®ã¨ç解ãã¦ãã¾ãã
- event-processor-modeï¼çºè¡ããã¤ãã³ãã®DBä¿åã¨Kafkaéä¿¡ã
- åä¸ã¹ã¬ããã§è¡ããï¼SUBSCRIBINGï¼
- å¥ã¹ã¬ããã§éåæã«è¡ããï¼TRACKINGï¼
- confirmation-modeï¼ã¤ãã³ãçºè¡å¦çã
- Kafkaéä¿¡æåãã¦ã¯ããã¦å®äºæ±ãã¨ãããï¼WAIT_FOR_ACK or TRANSACTIONALï¼
- Kakfaéä¿¡æåãå¾ ããã«å®äºæ±ãã¨ãããï¼NONEï¼
ãã®ï¼ã¤ã®è¨å®ã®çµã¿åããã«ãããKafkaéä¿¡ã失æããå ´åã®æåãå¤ãã£ã¦ãã¾ãã ãªãããããã®è¨å®ã§ããKafkaéä¿¡ã失æããå¾ã¯ãAxonãèªåã§ãªãã©ã¤ãç¶ãã¾ãã
ä¾ãã°ãæ¤è¨¼æã«æ³å®ãã¦ããã¦ã¼ã¹ã±ã¼ã¹ã§ã¯ãKafkaéä¿¡ã¨ã©ã¼çºçæç¹ã§ã¨ã©ã¼ãã°åºåãã¦æ¤ç¥ã¯ãããããKafkaéä¿¡ã失æããã ãã§ããã°ãå¦çã¯ç¶ç¶ãããï¼APIããªã¬ã®å¦çãªã®ã§ãAPIã®æåã¬ã¹ãã³ã¹ã¯è¿ãããï¼ã¨èãã¦ãã¾ããã ãã®å ´åã¯ãevent-processor-modeã¯SUBSCRIBINGãconfirmation-modeã¯WAIT_FOR_ACKã«è¨å®ããã®ãããã¨æããã¾ãã
æ©è½ã»å¦çã«ãããKafkaéä¿¡ã®å¤±ææã®å½±é¿ã«å¿ãã¦ãå³ææ¤ç¥ããã¼ã«ããã¯ã®è¦å¦ãªã©ãèæ ®ãã¦è¨å®ãé¸æããå¿ è¦ãããã¾ãã
ã¾ããAxonã¨ããããKafkaéä¿¡ã«ãããè¨å®ã§ãããacksã®è¨å®ãèããæ¹ãããããã§ãã ãã¡ããç°¡åã«è¨ãã¨ãKafkaå´ã§ã¤ãã³ãã®ã¬ããªã±ã¼ã·ã§ã³ãå®äºãã¦ã¯ããã¦éä¿¡å®äºæ±ãã¨ãããï¼ALLï¼ããããå¾ ããã«éä¿¡å®äºæ±ãã¨ãããï¼0 or 1ï¼ãã ã¨ç解ãã¦ãã¾ãã
ä¿å ¨æ§ã¨ããã©ã¼ãã³ã¹ã®ãã¬ã¼ããªãã¨ãªãããã§ããããã¾ã®ã¨ããæ§è½è¦ä»¶ã¯ãã»ã©é«ããªãã®ã§ãããã©ã¼ãã³ã¹ããæ¬ æãé¿ãããã¨ãåªå ããALLã«ããã®ãããããã§ãã
Subscriberï¼Kafkaã®ç¨èªã§ã¯Consumerï¼å´
Axonã§Kafkaããã¤ãã³ããåä¿¡ï¼åå¾ï¼ããããã§ã®ä¸»ãªè¨å®ã¯ãKafkaMessageSourceã®ç¨®é¡ã®é¸æã§ãã
大ããåãã¦ä»¥ä¸ã®ï¼ç¨®é¡ãããã®ã§ããï¼Axonã®ããã¥ã¡ã³ãã¯ãã¡ãï¼ã ãã®ï¼ã¤ã®éãã¯ããªãã»ããï¼Consumerããããã¯å ã®ã©ã®ã¡ãã»ã¼ã¸ã¾ã§ãå¦çãããï¼ã®ç®¡çæ¹æ³ã ã¨ç解ãã¦ãã¾ãã
- SubscribableKafkaMessageSourceï¼Kafkaå´ã§ãConsumer Groupæ©è½ã使ç¨ãã¦ç®¡çãã
- StreamableKafkaMessageSourceï¼Consumerã¢ããªã±ã¼ã·ã§ã³ï¼Axonï¼å´ã§ãDBï¼token_entryãã¼ãã«ï¼ã使ç¨ãã¦ç®¡çãã
主ãªã¡ãªããã»ãã¡ãªããã¨ãã¦ä»¥ä¸ãªã©ãããã¾ãã
- SubscribableKafkaMessageSource
- è¤æ°ãã¼ãåæ£ãKafkaããã£ã¦ããã
- ï¼ãã¼ãã£ã·ã§ã³ã®å ¨ã¦ã®ãã¼ã¿ãï¼ã¹ã¬ããã§å¦ç
- Axonã®Replayæ©è½ã使ããªã
- Consumerã®ã¤ãã³ãå¦çã®ã¨ã©ã¼æã®ãªãã©ã¤ã«ã¯Kafkaã¸ã®commitãèªåã§å¶å¾¡ããå¿ è¦ããã
- StreamableKafkaMessageSource
- è¤æ°ãã¼ãåæ£ãã¢ããªã±ã¼ã·ã§ã³å´ã§å¶å¾¡ããé¨åãèªåã§å®è£ ããå¿ è¦ããã
- ï¼ãã¼ãã£ã·ã§ã³ã®ãã¼ã¿ãè¤æ°ã¹ã¬ããã§ä¸¦åå¦çã§ãã
- Axonã®Replayæ©è½ã使ãã
- Consumerã®ã¤ãã³ãå¦çã®ã¨ã©ã¼æã®ãªãã©ã¤ãDLQ使ç¨ãAxonããã£ã¦ããã
Axonãæ¨å¥¨ãã¦ããã®ã¯StreamableKafkaMessageSourceãªã®ã§ãConsumerå´ã§DBã使ããããªããªã©ã®è¦ä»¶ããªããã°ããã¡ããé¸ã¶ã®ãããããã§ãã
ãã ããè¤æ°ãã¼ãåæ£ã¨Replayæ©è½ã«ã¤ãã¦ã¯ãå®è£ ããããã§ä»¥ä¸ã®ãããªèª²é¡ãè¦ã¤ããã¾ããã
- è¤æ°ãã¼ãåæ£ï¼è¤æ°ãã¼ãéã§è² è·ãå¹³æºåããå¦çãå®æçã«å®è¡ããå¿ è¦ãããã
- Replayæ©è½ï¼è¤æ°ãã¼ãã§åãã¦ããå ´åãConsumerå¦çãå ¨ã¦ã®ãã¼ãã§åæ¢ãã¦ããReplayãéå§ããå¿ è¦ãããã
å½åã¯ãAPIãµã¼ãã¨ãã¦ãã¼ããã©ã³ãµã¼ãå©ç¨ãã¦è¤æ°ãã¼ãã§è² è·åæ£ãã¦ããã¢ããªã±ã¼ã·ã§ã³ã«å¯¾ãã¦ãAxonãå°å ¥ããæ³å®ã ã£ãã®ã§ãConsumerã¨ãã¦ã®å¦çãè¤æ°ãã¼ãã§åæ£ããããã¨èãã¦ãã¾ããã
ã§ãããä¸è¨ã®æéãèããã¨ãConsumerå°ç¨ã®ãµã¼ããå¥éç«ã¦ãããè² è·ï¼ã¤ãã³ãæµéï¼ãå°ãªããã°è¤æ°ãã¼ãã®ãã¡1ãã¼ãã®ã¿ã§å¦çããæ¹ãã·ã³ãã«ã§ããããããã¾ããã ãã®å ´åã§ãããã¼ããé害ããªãªã¼ã¹ã§åæ¢ããéã«ã¯ãèªåã§å¥ãã¼ããå¼ãç¶ãã§å¦çãç¶ç¶ãã¦ããã¾ãã
ã¢ããªã¹ï¼PHPï¼ããã©ãå©ç¨ããã
Axonã¯ç¾ç¶ã¯JavaãKotlinã«ããå ¬å¼ã«å¯¾å¿ãã¦ããªããããPHPã§ä½ãããã¢ããªã¹ãGoã®ãã¤ã¯ããµã¼ãã¹ã«ã¤ãã¦ã¯ãAxonã¨ã®ã¢ããã¿ã¼ã¨ãªãããã»ã¹ãç¨æããå¿ è¦ãããããã§ãã
PHPããã³Goããç´æ¥Kafkaã«æ¥ç¶ããããã®ã©ã¤ãã©ãªãåå¨ãã¾ãããã§ããã°ã¤ãã³ãé£æºãããããã§Axonã®æ©è½ãæ´»ããããã¨ããã§ãã
Publisherï¼Kafkaã®ç¨èªã§ã¯Producerï¼å´
ã¢ããªã¹ãPublisherå´ã¨ãªãå ´åã¯ãDebeziumãå©ç¨ããCDCã§ããã©ã³ã¶ã¯ã·ã§ã³ãã°ï¼MySQLãªã®ã§binlogï¼ãKafkaã«éä¿¡ããæ¡ãããã¾ãã Debeziumã¯Kafka Connectã®ãã©ã°ã¤ã³ã¨ãã¦æä¾ããã¦ãããããMSKã®å ´åã¯MSK Connectãå©ç¨ãã¦èµ·åãããã¨ãã§ãã¾ãã
DBã®æ´æ°ãã¤ãã³ãã¨ãã¦æ±ããã¨ãã§ãã¾ããã課é¡ãããã¾ãã
ã¾ããï¼ã¤ã®éç´ã®æ´æ°ãè¤æ°ãã¼ãã«ã®æ´æ°ã¨ãªãå ´åãè¤æ°ãã¼ãã«ã®æ´æ°ãã°ããï¼ã¤ã®ãã¡ã¤ã³ã¤ãã³ãã解éãã¦çæããã®ãé£ããå¯è½æ§ãããã¾ãã ããããã¢ããªã¹ã®ä¸ã«ã¯ã¾ã DDDã«ãã¨ã¥ãå®è£ ã«ãªã£ã¦ããªãé¨åãå¤ãã®ã§ãéç´ããã¡ã¤ã³ã¤ãã³ãã®æ¦å¿µã«æ²¿ã£ããã¼ãã«æ´æ°ã¨ãªãããã«ããããã«ã¯ãã¾ããªãã¡ã¯ã¿ãªã³ã°ãå¿ è¦ã¨æããã¾ãã
ã¾ããAxonã¯ãAxonã®ã¤ãã³ãã¨ãã¦çæãããå½¢å¼ã®Kafkaã¡ãã»ã¼ã¸ããå¦çããªããããDebeziumã®ã¡ãã»ã¼ã¸ãAxonã®ã¤ãã³ãã«å¤æããå¦çãå¿ è¦ã¨ãªãã¾ãã ã¢ããªã¹å´ã®ãªãã¡ã¯ã¿ãªã³ã°ãé£ããå ´åã¯ããã®ã¿ã¤ãã³ã°ã§è¤æ°ãã¼ãã«ã®æ´æ°ãã°ãä¸éãã¼ãã«ã«æ´å½¢ã»èç©ãã¤ã¤ããã¡ã¤ã³ã¤ãã³ãï¼Axonã®ã¤ãã³ãï¼ã¨ãã¦å¤æãã¦Kafkaã«å ¥ãç´ãæ¹æ³ãèãããã¾ãã
Subscriberï¼Kafkaã®ç¨èªã§ã¯Consumerï¼å´
ã¢ããªã¹ãSubscriberå´ã¨ãªãå ´åã¯ãKafkaããAxonã®ã¤ãã³ããåä¿¡ããå¥æ©ã§ã¢ããªã¹ã®APIãå¼ã³åºãå¿ è¦ãããã¾ãã
Kafkaã®ã¡ãã»ã¼ã¸ãç´æ¥åå¾ãã¦å¦çããã®ã§ãªããAxonçµç±ã§åãåããã¨ã§ãAxonã®ãªãã©ã¤ãDLQãReplayçã®æ©è½ãå©ç¨ãããã¨ãã§ãã¾ãã ãã®å ´åããã®Axonãå©ç¨ããã¢ããã¿ã¼ããã»ã¹ãSubscriberã¨ãªãè¤æ°ãã¼ã ã§å ±æãããã¨ã«ãªããããªã®ã§ãä¾åã競åã«æ³¨æãå¿ è¦ã¨ãªãç¹ãæ¸å¿µã§ãã
Axonã®æ©è½ãä¸è¦ã ã£ãã代æ¿ã§ããå ´åã¯ãMSKããªã¬ã¼ã使ç¨ããLambdaããAPIãå¼ã¶ãã¨ãã§ãã¾ãã ãã®å ´åã¯ããããã¯ã¨Subscriberã®çµã¿åãããã¨ã«Lambdaä½æãå¿ è¦ã«ãªãããã§ãããã®ãããã¯ååè¨äºã«è¨è¼ããEventBrigeå©ç¨ãã¤API Destinationsãå©ç¨ããªãå ´åã¨åæ§ã§ãã
ãã®ä»
ä»ã«ããã¤ãã³ãã®ã¹ãã¼ããã©ã管çããããKafkaãä»ããçµåãã¹ããCIã§ã©ãè¡ãããã¨ãã£ã課é¡ãããã¾ããããæ¯è¼ç容æã«è§£æ±ºã§ããã®ã§ãè¨äºã®åéã®é½åãããå²æããã¦ããã ãã¾ãã
ã¾ã¨ã
MSKããã³Axonã«å¯¾ãã¦ã調æ»ãæ¤è¨ãå¿ è¦ã¨ãªã£ãé¨åã«ã¤ãã¦è¨è¼ãã¾ããã
ããã£ãç¹
- Axonã®æ©è½ã®ã«ãã¼ç¯å²ãåºããèªåã§å®è£ ããå¿ è¦ãããé¨åãå°ãªã
- Kotlinã¨SpringBootã§å®è£ ãã¦ãããã¤ã¯ããµã¼ãã¹ã¸ã®çµã¿è¾¼ã¿ãç¨æ
- private subnetå ã§ECSãµã¼ãã¹ã¨MSKãç´æ¥éä¿¡ã§ããã®ã§ãã»ãã¥ãªãã£ãNWæ§æã®èæ ®ã»å¯¾å¿ãæ¯è¼çå°ãªã
æ°ã«ãªãç¹
- ã¢ããªã¹ã¨ã®é£æºããããã®æ¤è¨ã»æ§ç¯è¦ç´ ãå¤ã
- MSKã®ä¿å®ã®é£æ度ãå°æ¥æ§ã«ä¸å®ããã
- ç¹ã«ã¹ã¢ã¼ã«ã¹ã¿ã¼ãæç¹ã§ã¯æéãé«ã
ææ³ã¨ãã¦ããã¯ãKafkaã¯ã¡ãã»ã¼ã¸ã³ã°åºç¤ã¨ãã¦æçãã¦ãã¾ãããAxonãå©ç¨ã容æã§DDDãå¿åãã¤ã¤ã¤ãã³ãé£æºããããã³ãã¢ã³ã®ç¾ç¶ã«ãã£ããããã¨æãã¾ãããã¤ãã³ãé£æºåºç¤ã¨ãã¦å©ç¨ããããã§ã®å®ç¾æ§ã¯é«ãã¨æãã¾ãã
ãã ãã©ã¡ããã使ãå§ããããã§ã¯ããããªãã«å¦ç¿ãå¿ è¦ãªç¹ã¯ãã¼ãã«ã«ã¯ãªã£ã¦ãã¾ãããã§ããå¦ç¿ã³ã¹ãã¨ããè¨èã¯ãã¾ã使ããããªãã§ãããæè³ã¨ãã¦ã¨ã³ã¸ãã¢ã«ååãã«åãçµãã§ããããããåãããã¯å¿ è¦ããããã¾ããã
å°ãªãã¨ãKafkaã«ã¤ãã¦å¦ã¶ãã¨ã¯ãã¡ãã»ã¼ã¸ã³ã°ãåæ£å¦çã«ã¤ãã¦åå¼·ã«ãªããã¨ãå¤ãã§ãããAxonãä»å¾ã©ãã¾ã§åºã¾ããã¯æªç¥ã§ãããCQRS/ESã«ãã£ã¬ã³ã¸ãããã£ããã«ã§ããã°ã¨æã£ã¦ãã¾ãã
次ã¯æçµåã¨ãã¦ãEventBridgeã¨MSKã®æ¯è¼ã®ã¾ã¨ãã¨ãæè¡é¸å®ã®çµè«ããä¼ãããäºå®ã§ãã