Vert.x Examples

repository·5.x·Indexed 25 days ago

https://github.com/vert-x3/vertx-examples

A 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.

Tokens
102.5K
Snippets
344
Records
477
Agent score
86%

What's inside vertx-examples

  1. Overview of Vert.x RxJava3 extension examples

    5.x

    This 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, and Completable with 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-examples module.

  2. Overview of Vert.x Circuit Breaker

    5.x

    Vert.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).
  3. Overview of Vert.x Config capabilities

    5.x

    Vert.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.
  4. Explore Sock.js Proxy Service example files

    5.x

    The 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)
  5. Explore Vert.x 5 examples by module

    5.x

    This 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 Client for 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 2 or RxJava 3 APIs.
    • Kotlin: Using Kotlin coroutines (e.g., in JDBC applications).
    • Messaging & Protocols: gRPC, AMQP, MQTT, Kafka, and Zipkin tracing.
    • Databases: Redis, MongoDB, and Reactive SQL Client (PostgreSQL/MySQL).
    • Integrations: Spring ecosystem, Apache Camel bridge, and GraphQL (via Vert.x Web GraphQL and GraphQL-Java).
    • Other: Mail (SMTP/TLS/SSL), JPMS (Java Module System), and GraphQL.
  6. Understand the Kafka Monitoring Dashboard architecture

    5.x

    The monitoring dashboard example is composed of three main components:

    • MainVerticle: The entry point. It starts a Kafka broker and configures the DashboardVerticle and MetricsVerticle with 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 DashboardVerticle and MetricsVerticle would be executed as separate processes with their own configurations.

  7. Extend Vert.x Shell with custom commands

    5.x

    Vert.x Shell can be extended by implementing custom commands. Examples of command patterns include:

    • Interacting with APIs: Using HttpClient to implement commands like wget <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 NetClient to stream remote content (e.g., starwars) and handling EventType.SIGINT to terminate the command on Ctrl-C.
    • Terminal Control: Using the TermServer for total control over the user terminal, which provides simple terminal capabilities instead of shell-like features.
  8. Explore Vert.x MQTT examples

    5.x

    The mqtt-examples directory 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
  9. Explore Vert.x virtual thread client examples

    5.x

    The following examples demonstrate how to use specific Vert.x clients in conjunction with virtual threads:

    • HTTP client: See HttpClientExample.java for using the Vert.x HTTP client.
    • Web client: See WebClientExample.java for using the Vert.x Web client.
    • SQL client: See SqlClientExample.java for using the Vert.x SQL client.