ããã«ã¡ã¯ãRed Hatã§ã½ãªã¥ã¼ã·ã§ã³ã¢ã¼ããã¯ãããã¦ããææ¬ æã§ããååæ¸ããRed Hatã®Service Registryã®è¨äºã§ã¯Service Registryã®æ¦è¦ã¨åºæ¬çãªä½¿ãæ¹ã«ã¤ãã¦è§£èª¬ãã¾ããããä»æã®èµ¤å¸½ã¨ã³ã¸ãã¢ããã°ã®è¨äºã§ã¯ãQuarkusã®ã¢ããªã±ã¼ã·ã§ã³ããService RegistryãKafkaã¨çµã¿åããã¦ä½¿ç¨ããæ¹æ³ã«ã¤ãã¦ãç´¹ä»ãããã¨æãã¾ãããªããæ¬è¨äºã®å 容ã¯ãUsing Quarkus applications with Kafka instances and Red Hat OpenShift Service Registryããã¼ã¹ã¨ãã¦ãã¾ãã
äºåæºå
Service Registryãå©ç¨ããã¢ããªã±ã¼ã·ã§ã³ããã«ããé²ããåã«ã以ä¸ã®äºåæºåããã¦ããã¾ãããã
ããã¼ã¸ããµã¼ãã¹ã§ã®ç°å¢ã®ä½æ
Red Hat Hybrid Cloud Consoleã§ä»¥ä¸ã®æºåããã¦ããã¦ãã ããã
- Kafkaã¤ã³ã¹ã¿ã³ã¹ã®ä½æ
- Service Registryã¤ã³ã¹ã¿ã³ã¹ã®ä½æ
- Service Accountã®ä½æ (Kafkaã¨Service Registryã§å ±é)
- Kafkaã¤ã³ã¹ã¿ã³ã¹ã¨Service Registryã¤ã³ã¹ã¿ã³ã¹ã§ã®ã¢ã¯ã»ã¹æ¨©ã®è¨å®
ãªããããã¾ã§ã®èµ¤å¸½ããã°ã§ä¸è¨ã®å®æ½æé ã«ã¤ãã¦ãç´¹ä»ãã¦ãã¾ãã®ã§ã以ä¸ã®è¨äºããåç §ãã ããã
Kafkaã¤ã³ã¹ã¿ã³ã¹ã®ã¢ã¯ã»ã¹æ¨©ã®è¨å®ç»é¢ããManage access
ãã¯ãªãã¯ããä½æãããµã¼ãã¹ã¢ã«ã¦ã³ãã使ç¨ãã¦Consumer/Producerããããã®ã¢ããªã±ã¼ã·ã§ã³ã¢ã¯ã»ã¹ã§ããããã«ãããã¯ã¨Consumer groupã«å¯¾ãã¦ã以ä¸ã®ããã«ã¢ã¯ã»ã¹æ¨©ãè¨å®ãã¦ããã¾ãã
ãªããService Registryã§ã®ãµã¼ãã¹ã¢ã«ã¦ã³ãã®è¨å®ã§ã¯ã使ç¨ãããµã¼ãã¹ã¢ã«ã¦ã³ãã«å¯¾ãã¦Manager権éãä»ä¸ãã¦ããã¦ãã ããã
ãã¼ã«ã«ã®ã¢ããªã±ã¼ã·ã§ã³éçºç°å¢
ãã¼ã«ã«ãã·ã³ã§ã¢ããªã±ã¼ã·ã§ã³ããã«ãããããã®ç°å¢ã¨ãã¦ã¯ä»¥ä¸ãç¨æãã¦ããã¦ãã ããã
- OpenJDK 11 以ä¸
- Apache Maven 3.8 以ä¸
- IDE (Visual Studio CodeãEclipseãªã©)
ã½ã¼ã¹ã³ã¼ãã®ã¤ã³ãã¼ã
äºåæºåãã§ããããã¾ãã¯Red Hatã®Application Servicesã®Githubãªãã¸ããªããã½ã¼ã¹ã³ã¼ããã¤ã³ãã¼ããã¾ãã
git clone https://github.com/redhat-developer/app-services-guides app-services-guides
ãªãããã®Application Servicesã®Githubãªãã¸ããªã«ã¯ãRed Hatã®ããã¼ã¸ãKafkaãService Registryãå©ç¨ããããã®ã¬ã¤ãããµã³ãã«ã³ã¼ããããã¾ãã®ã§ããã²åèã«ãã¦é ããã°ã¨æãã¾ãã
ããã§ä½¿ç¨ãããµã³ãã«ã³ã¼ãã¯code-examplesãã©ã«ãã«ããquarkus-service-registry-quickstartã¨ããååã®ããã¸ã§ã¯ãã§ãã®ã§ããã®ãã©ã«ããVisual Studio Codeã«åãè¾¼ãã¨ä»¥ä¸ã®ããã«ãKafkaã®Producerã¨Consumerã®ã¢ããªã±ã¼ã·ã§ã³ãã©ã«ãã表示ããã¾ãã
Kafkaã¨Service Registryã«ã¢ã¯ã»ã¹ããããã®è¨å®
ã§ã¯æ¬¡ã«ããã®ãµã³ãã«ã®Quarkusã¢ããªã±ã¼ã·ã§ã³ããKafkaã¨Service Registryã«ã¢ã¯ã»ã¹ããããã®è¨å®ããã¦ããã¾ããããRed Hatã®ããã¼ã¸ããµã¼ãã¹ã¨ãã¦æä¾ããã¦ããKafkaã¨Service Registryã«ã¢ã¯ã»ã¹ããã«ã¯ãäºåæºåã®ã¨ããã§ç¨æããKafkaã¤ã³ã¹ã¿ã³ã¹ã¨Service Registryã¤ã³ã¹ã¿ã³ã¹ã¸ã®æ¥ç¶æ å ±ã¨Service Account (Kafkaã¨Service Registryã§å ±é)ãå¿ è¦ã¨ãªãã¾ãã®ã§ãHybrid Cloud Consoleã§å¤ã確èªãã¦ããããã®æ å ±ãåå¾ãã¦ããã¾ãããã
- <bootstrap_server> : 使ç¨ããKafkaã¤ã³ã¹ã¿ã³ã¹ã®Bootstrap serverã®ãã¹ãå
- <service_registry_url> : 使ç¨ããService Registryã¤ã³ã¹ã¿ã³ã¹ã®Core Registry APIã®URLã®FQDNã¾ã§
- <service_registry_core_path> : Service Registryã®Core Registry APIã®URLã¸ã®ãã¹ (é常 "/apis/registry/v2")
- <oauth_token_endpoint_uri> : OAuthèªè¨¼ã§ä½¿ç¨ãããSASL/OAUTHBEARERãã¼ã¯ã³ã®ã¨ã³ããã¤ã³ãURL
- <client_id>: Service Accountã®Client ID
- <client_secret>: Service Accountã®Client Secret
Producer/Consumerããããã®ã½ã¼ã¹ã³ã¼ãã®ãã©ã«ã(src/main/resources)ã«ããapplication.propertiesãã¡ã¤ã«ã«ã¯ãæ¢ã«å¿ è¦ãªæ¥ç¶æ å ±ãç°å¢å¤æ°ã使ç¨ãã¦ã¢ããªã±ã¼ã·ã§ã³ã«æ¸¡ããããã«ãªã£ã¦ãã¾ãã®ã§ãã¿ã¼ããã«ããç°å¢å¤æ°ãè¨å®ãã¦ããã¾ãï¼ä»¥ä¸ã®æ¥ç¶æ å ±ã¯ããããåå¾ããå¤ã«å¤æ´ãã¦ããç°å¢å¤æ°ãè¨å®ãã¦ãã ããï¼ã
$ export KAFKA_HOST=<bootstrap_server> $ export SERVICE_REGISTRY_URL=<service_registry_url> $ export SERVICE_REGISTRY_CORE_PATH=/apis/registry/v2 $ export RHOAS_SERVICE_ACCOUNT_OAUTH_TOKEN_URL=<oauth_token_endpoint_uri> $ export RHOAS_SERVICE_ACCOUNT_CLIENT_ID=<client_id> $ export RHOAS_SERVICE_ACCOUNT_CLIENT_SECRET=<client_secret>
Kafkaãããã¯ã®ä½æ
ãµã³ãã«ã¢ããªã±ã¼ã·ã§ã³ã§ä½¿ç¨ããKafkaãããã¯ãOpenShift Streams for Apache Kafkaã§ä½æãã¾ããHybrid Cloud Consoleã®Kafkaã¤ã³ã¹ã¿ã³ã¹ã«ã¢ã¯ã»ã¹ããquotes
ã¨ããååã®ãããã¯ãä½æãã¾ããããPartitionsæ°ãMessage retentionãReplicaã®å¤ã«ã¤ãã¦ã¯ãããã§ã¯ããã©ã«ãã®ã¾ã¾ã§æ§ãã¾ããã
ãµã³ãã«ã®Quarkusã¢ããªã±ã¼ã·ã§ã³ã®å®è¡
ãã®ãµã³ãã«ã¢ããªã±ã¼ã·ã§ã³ã§ã¯ã以ä¸ã®ãããªæ§æã«ãªã£ã¦ãã¾ãã
- Consumer (QuotesResourceã¯ã©ã¹ã§å®è£ ) : quoteãããã¯ããã¡ãã»ã¼ã¸ãåå¾ãããã®å¤ãServer-Sent Eventsã使ç¨ãã¦ãã©ã¦ã¶ç»é¢ã«è¡¨ç¤º
- Producer (QuotesProducerã¯ã©ã¹ã§å®è£ ) : 5ç§ééã§Quote (è¦ç©ãã) ã®å¤ãã©ã³ãã ã§çæããquoteãããã¯ã«ãããªãã·ã¥
æ¥ç¶æ å ±ã®è¨å®ãã§ãããã以ä¸ã®ã³ãã³ãã§Consumerã¢ããªã±ã¼ã·ã§ã³ãå®è¡ãã¦ã¿ã¾ãããï¼ç°å¢å¤æ°ã®è¨å®ããå¿ããªãï¼ã
$ cd ~/code-examples/quarkus-service-registry-quickstart/consumer $ mvn quarkus:dev
Consumerã¢ããªã±ã¼ã·ã§ã³ãæ£å¸¸ã«èµ·åããããã¿ã¼ããã«ã¯ä»¥ä¸ã®ãããªç»é¢ã«ãªã£ã¦ãããã¨æãã¾ãã
次ã«ãã©ã¦ã¶ãã http://localhost:8080/quotes.html ã«ã¢ã¯ã»ã¹ãã㨠Quotes ã®å¤ã表示ããããã«ãªã£ã¦ãã¾ããConsumerã¢ããªã±ã¼ã·ã§ã³èµ·åæã«ã¯Producerã¢ããªã±ã¼ã·ã§ã³ãèµ·åãã¦ããªããããå¤ã¯ä½ã表示ããã¾ããã
ã§ã¯æ¬¡ã«ãConsumerã¢ããªã±ã¼ã·ã§ã³ãå®è¡ããã¾ã¾ã¿ã¼ããã«ãããä¸ã¤èµ·åãã以ä¸ã®ã³ãã³ãã§Producerã¢ããªã±ã¼ã·ã§ã³ãå®è¡ãã¦ã¿ã¾ãããï¼ç°å¢å¤æ°ã®è¨å®ããå¿ããªãï¼ã
$ cd ~/code-examples/quarkus-service-registry-quickstart/consumer $ mvn quarkus:dev
Producerã¢ããªã±ã¼ã·ã§ã³ãæ£å¸¸ã«èµ·åããã¨ãã¿ã¼ããã«ã«ã¯ä»¥ä¸ã®ããã«è¡¨ç¤ºããã¾ãã
Consumerã¢ããªã±ã¼ã·ã§ã³ã«å«ã¾ãã¦ããWebã¢ããªã±ã¼ã·ã§ã³ã«ãã©ã¦ã¶ã§ã¢ã¯ã»ã¹ããã¨ãProducerã¢ããªã±ã¼ã·ã§ã³ãã5ç§ééã§Quotesã®å¤ãçæãããå¤ãã以ä¸ã®ããã«è¡¨ç¤ºãããã®ã確èªã§ãããã¨æãã¾ãã
Hybrid Cloud Consoleã§Service Registryã¤ã³ã¹ã¿ã³ã¹ãè¦ã¦ã¿ãã¨ããµã³ãã«ã¢ããªã±ã¼ã·ã§ã³ã§å©ç¨ããã¦ããQuotesã®ã¹ãã¼ããã¢ã¼ãã£ãã¡ã¯ãã¨ãã¦ç»é²ããã¦ãããã¨ã確èªã§ãã¾ãã
ãã®ãµã³ãã«ã¢ããªã±ã¼ã·ã§ã³ã§ã¯ãAvroãã©ã¼ãããã®ã¹ãã¼ãã®ã·ãªã¢ã©ã¤ãºã¨ãã·ãªã¢ã©ã¤ãºã«ããã¦ãApicurioã®Service Registryã®æ©è½ãå©ç¨ããã¦ãããProducerã¨Consumerã®ã¢ããªã±ã¼ã·ã§ã³ã®application.propertiesã§ã¯ããããã io.apicurio.registry.serde.avro.AvroKafkaSerializer
㨠io.apicurio.registry.serde.avro.AvroKafkaDeserializer
ã使ç¨ããã¦ãã¾ãããã®ãµã³ãã«ã¢ããªã±ã¼ã·ã§ã³ãå®è¡ãããã¿ã¤ãã³ã°ã§Quotesã®Avroã¹ãã¼ããService Registryã«ç»é²ããããããå
ã«ã¹ãã¼ãã«å¯¾ãã¦ã«ã¼ã«ãè¨å®ãããã¨ãã§ããããã«ãªããã¹ãã¼ãã®é²åã«ã対å¿ãã¦ããã¨ãã§ããããã«ãªãã¾ãã