Vert.x Examples
repository·5.x·Indexed 25 days ago
https://github.com/vert-x3/vertx-examplesA collection of examples demonstrating usage patterns for Vert.x, including gRPC (request/response, streaming, transcoding, SSL), Kotlin Coroutines, Service Proxy Provider, AMQP Client messaging, Camel Bridge (RSS feeds and RMI), Cassandra Client (simple queries, prepared statements, and streaming), Circuit Breaker implementation, and ConfigRetriever for application configuration.
What's inside vertx-examples
- Vert.x Web GraphQL extends Vert.x Web with the GraphQL-Java library, allowing you to build GraphQL servers within the Vert.x ecosystem.
Overview of Vert.x RxJava3 extension examples
5.xThis module provides examples for the Vert.x RxJava 3 extension, which offers 'Rxified' versions of the standard Vert.x APIs. These examples demonstrate how to use RxJava 3 types like
Single,Flowable, andCompletablewith Vert.x components such as the Web Client, HTTP server, Event Bus, Database clients, and Schedulers.Note: These examples specifically use the RxJava 3 API. For RxJava 2, refer to the
rxjava-2-examplesmodule.Overview of Vert.x Circuit Breaker
5.xVert.x Circuit Breaker is an implementation of the Circuit Breaker pattern designed for Vert.x. It monitors the success and failure of asynchronous operations to prevent cascading failures in a system. When a failure threshold is reached, the circuit 'opens', and subsequent calls are immediately diverted to a fallback method or fail fast.
Supported failure types include:
- Failures explicitly reported by your code.
- Exceptions thrown by your code.
- Uncompleted futures (timeouts).
Overview of Vert.x Config capabilities
5.xVert.x Config is a configuration framework for Vert.x applications that supports:
- Multiple syntaxes: JSON, properties, YAML, and HOCON.
- Multiple stores: Files, directories, HTTP, Git, Redis, system properties, and environment properties.
- Customizable processing: Define the order of configuration loading and how values are overloaded.
- Runtime reconfiguration: Support for updating configuration while the application is running.
Use Vert.x OpenAPI Router for automated validation
5.xFor a more integrated approach to request validation, it is recommended to use the Vert.x OpenAPI Router. This provides a higher-level abstraction for routing and validation compared to manualOpenAPIContractusage.Explore Sock.js Proxy Service example files
5.xThe following files are key to understanding the Sock.js Proxy implementation:
- Java Server:
src/main/java/io/vertx/example/web/proxies/Server.java - TypeScript Client App:
src/main/java/io/vertx/example/web/proxies/client/main.ts - Generated TypeScript Proxy:
src/main/java/io/vertx/example/web/proxies/client/my_service-proxy.ts(This is the proxy generated by Vert.x)
Configuration files for the build process include:
package.json(dependencies)webpack.config.js(Webpack configuration)tsconfig.json(TypeScript compiler configuration)
- Java Server:
Explore Vert.x 5 examples by module
5.xThis repository provides specialized examples for various Vert.x features. Use the following module categories to find specific implementations:
- Core: Basic Vert.x Core functionality.
- Web: Building web applications with
Vert.x-Web. - Web Client: Using the
Vert.x Web Clientfor HTTP requests. - Service Resolver: Discovering service endpoints using a resolver.
- Service Proxy: Implementing and consuming published services via proxies.
- Virtual Threads: Using Vert.x with Java virtual threads.
- Testing: Asynchronous testing with
Vert.x JUnit 5. - Reactive Streams: Using
RxJava 2orRxJava 3APIs. - Kotlin: Using Kotlin coroutines (e.g., in JDBC applications).
- Messaging & Protocols:
gRPC,AMQP,MQTT,Kafka, andZipkintracing. - Databases:
Redis,MongoDB, and ReactiveSQL Client(PostgreSQL/MySQL). - Integrations:
Springecosystem,Apache Camelbridge, andGraphQL(viaVert.x Web GraphQLandGraphQL-Java). - Other:
Mail(SMTP/TLS/SSL),JPMS(Java Module System), andGraphQL.
Understand the Kafka Monitoring Dashboard architecture
5.xThe monitoring dashboard example is composed of three main components:
MainVerticle: The entry point. It starts a Kafka broker and configures theDashboardVerticleandMetricsVerticlewith their respective consumer and producer configurations.MetricsVerticle: Uses the Kafka producer API to produce metrics in JSON format.DashboardVerticle: Uses the Kafka consumer API to consume metrics and forwards them to a monitoring dashboard using the Vert.x Event Bus.
Note: In production environments, the Kafka broker is typically managed externally, and the
DashboardVerticleandMetricsVerticlewould be executed as separate processes with their own configurations.Extend Vert.x Shell with custom commands
5.xVert.x Shell can be extended by implementing custom commands. Examples of command patterns include:
- Interacting with APIs: Using
HttpClientto implement commands likewget <url>. - Periodic Data Pushing: Mimicking OS commands (like
top) by pushing periodic data to the Shell. - Capturing Keyboard Events: Implementing commands that capture user keyboard input (e.g.,
echokeyboard). - Streaming Data: Using
NetClientto stream remote content (e.g.,starwars) and handlingEventType.SIGINTto terminate the command on Ctrl-C. - Terminal Control: Using the
TermServerfor total control over the user terminal, which provides simple terminal capabilities instead of shell-like features.
- Interacting with APIs: Using
Explore Vert.x MQTT examples
5.xThe
mqtt-examplesdirectory contains several implementation patterns for MQTT servers and clients:Simple Echo
Demonstrates a basic server verticle that accepts connections and echoes back received messages.
- Server:
src/main/java/io/vertx/example/mqtt/simple/Server.java - Client:
src/main/java/io/vertx/example/mqtt/simple/Client.java
Full API Usage (App)
Demonstrates a more significant portion of both the Client and Server APIs.
- Server:
src/main/java/io/vertx/example/mqtt/app/Server.java - Client:
src/main/java/io/vertx/example/mqtt/app/Client.java
SSL Encrypted Connections
An implementation of the Simple echo pattern but using SSL to encrypt connections.
- Server:
src/main/java/io/vertx/example/mqtt/ssl/Server.java - Client:
src/main/java/io/vertx/example/mqtt/ssl/Client.java
- Server:
Explore Vert.x Mongo Client examples
5.xThis directory contains examples demonstrating how to use the Vert.x Mongo Client. The primary example is implemented inMongoClientVerticle.java.Explore Vert.x virtual thread client examples
5.xThe following examples demonstrate how to use specific Vert.x clients in conjunction with virtual threads:
- HTTP client: See
HttpClientExample.javafor using the Vert.x HTTP client. - Web client: See
WebClientExample.javafor using the Vert.x Web client. - SQL client: See
SqlClientExample.javafor using the Vert.x SQL client.
- HTTP client: See