### Starting a Zipkin Server with Docker Source: https://github.com/vert-x3/vertx-examples/blob/5.x/zipkin-examples/README.adoc Instructions to start a Zipkin server using Docker, which is required for monitoring Vert.x services. The server will be accessible on port 9411. ```bash > docker run -d -p 9411:9411 openzipkin/zipkin ``` -------------------------------- ### Asynchronous Vert.x Verticle Deployment Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc This example demonstrates how to deploy Vert.x verticles with asynchronous `start` and `stop` methods. This pattern is crucial for verticles that perform time-consuming initialization or cleanup, preventing the event loop from being blocked. ```Java src/main/java/io/vertx/example/core/verticle/asyncstart/DeployExample.java ``` ```Java src/main/java/io/vertx/example/core/verticle/asyncstart/OtherVerticle.java ``` -------------------------------- ### Compile and Run Vert.x Spring Application Source: https://github.com/vert-x3/vertx-examples/blob/5.x/spring-examples/spring-verticle-factory/README.adoc Use Maven to compile and execute the Vert.x Spring Verticle Factory example, starting the HTTP server. ```shell mvn compile exec:java@run ``` -------------------------------- ### Create Hello World Custom Shell Command Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc This example demonstrates a simple 'hello world' command that extends Vert.x Shell. After running the shell, connect via Telnet and execute the 'helloworld' command. ```Shell telnet localhost 3000 helloworld ``` -------------------------------- ### Vert.x Web Client Dependencies for Maven/Gradle Source: https://github.com/vert-x3/vertx-examples/blob/5.x/web-client-examples/README.adoc To use Vert.x Web Client in a Maven or Gradle project, the 'vertx-core' and 'vertx-web-client' artifacts are required. Additional template engine dependencies may be needed depending on the project setup. ```Dependency Specification Group ID: io.vertx Artifact ID: vertx-core Group ID: io.vertx Artifact ID: vertx-web-client ``` -------------------------------- ### Deploy Vert.x Shell Service via HTTP Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc This example shows how to deploy the Vert.x Shell service accessible via HTTP as a packaged Vert.x service. After deployment, point your browser to the specified URL and type 'help' within the shell to see available commands. ```Shell http://localhost:8080/shell.html ``` -------------------------------- ### Run ActiveMQ Artemis Docker Container Source: https://github.com/vert-x3/vertx-examples/blob/5.x/stomp-examples/README.adoc Starts an ActiveMQ Artemis server instance using Docker, exposing necessary ports for STOMP (61613) and its web console (8161). This server is required to run the Vert.x STOMP client examples. ```shell docker run -p 61613:61613 -p 8161:8161 apache/activemq-artemis:latest-alpine ``` -------------------------------- ### Launch Vert.x Camel Bridge RMI Example Source: https://github.com/vert-x3/vertx-examples/blob/5.x/camel-bridge-examples/README.adoc Command to launch the Vert.x Camel Bridge RMI example, which serves HTTP requests by invoking a Camel route interacting with an RMI service. This example demonstrates RPC support, inbound bridge configuration, and XML-based Camel Context definition. ```Shell java -jar target/camel-bridge-examples-5.0.0.jar run io.vertx.example.camel.rmi.RMIExample ``` -------------------------------- ### Start Jaeger Distributed Tracing Platform with Docker Source: https://github.com/vert-x3/vertx-examples/blob/5.x/opentelemetry-examples/README.adoc Provides a Docker command to run a Jaeger server, an open-source distributed tracing platform compatible with OpenTelemetry. It configures necessary port mappings and OTLP receiver endpoints for tracing data. ```shell docker run --rm --name jaeger \ -p 5778:5778 \ -p 16686:16686 \ -p 4317:4317 \ -p 4318:4318 \ -p 14250:14250 \ -p 14268:14268 \ -p 9411:9411 \ jaegertracing/jaeger:2.0.0 \ --set receivers.otlp.protocols.http.endpoint=0.0.0.0:4318 \ --set receivers.otlp.protocols.grpc.endpoint=0.0.0.0:4317 ``` -------------------------------- ### Add Vert.x MQTT Dependency Source: https://github.com/vert-x3/vertx-examples/blob/5.x/mqtt-examples/README.adoc Instructions for adding the Vert.x MQTT server and client dependency to a Maven or Gradle project. ```Maven/Gradle Group ID: io.vertx Artifact ID: vertx-mqtt ``` -------------------------------- ### Deploy Vert.x Shell Service via Telnet Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc This example shows how to deploy the Vert.x Shell service accessible via Telnet as a packaged Vert.x service. After deployment, connect using Telnet and type 'help' to see available commands. ```Shell telnet localhost 3000 help ``` -------------------------------- ### Querying the Vert.x Hello Service Source: https://github.com/vert-x3/vertx-examples/blob/5.x/zipkin-examples/README.adoc Demonstrates how to query the Hello service, an HTTP microservice that uses the Joke service, using curl. This service contributes traces from its HTTP server and HTTP client. ```bash > curl http://localhost:8081 ``` -------------------------------- ### Start Local SMTP Server for Testing Source: https://github.com/vert-x3/vertx-examples/blob/5.x/mail-examples/README.adoc This snippet starts a local 'fake' SMTP server on port 2526, primarily for testing and development. It logs incoming mail content to the console instead of actually sending emails. Users can remove this line to configure a different SMTP server. ```Java LocalSmtpServer.start(2526); ``` -------------------------------- ### Launch Vert.x Camel Bridge Feed Example Source: https://github.com/vert-x3/vertx-examples/blob/5.x/camel-bridge-examples/README.adoc Command to launch the Vert.x Camel Bridge Feed example, which reads RSS feeds, filters entries, extracts titles, and sends them to the event bus. This example demonstrates message production, outbound bridge configuration, SEDA support, filtering, and transformations. ```Shell java -jar target/camel-bridge-examples-5.0.0.jar run io.vertx.example.camel.feed.FeedExample ``` -------------------------------- ### Vert.x Custom ReadStream/WriteStream and Protocol Implementation Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Illustrates how to implement custom `ReadStream` and `WriteStream` interfaces in Vert.x to handle a specific prefix length protocol. The example defines a `Batch` object and demonstrates its wire format for communication between a `NetServer` and `NetClient`. ```Java src/main/java/io/vertx/example/core/net/stream/Batch.java ``` ```Java src/main/java/io/vertx/example/core/net/stream/BatchStream.java ``` ```Java src/main/java/io/vertx/example/core/net/stream/Server.java ``` ```Java src/main/java/io/vertx/example/core/net/stream/Client.java ``` ```APIDOC Length : uInt32 Type : byte ['O' for JsonObject | 'A' for JsonArray | 'B' for Buffer] Payload : Buffer ``` -------------------------------- ### HTTP/2 Push Server Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Illustrates an HTTP/2 server configured to push additional content, such as script.js, along with the main index.html to the client. This optimizes resource loading. ```Java src/main/java/io/vertx/example/core/http2/push/Server.java ``` -------------------------------- ### Run Vert.x gRPC Service with JPMS Source: https://github.com/vert-x3/vertx-examples/blob/5.x/jpms-examples/README.adoc A simple gRPC service example using Vert.x with JPMS. This example requires setting the `TEMPORARILY_DISABLE_PROTOBUF_VERSION_CHECK` environment variable. The snippet shows how to test the service using `grpcurl` and how to run it as a jlink application image for Mac/M1. ```Shell grpcurl -plaintext -d '{"name":"Julien"}' -proto src/main/proto/helloworld.proto localhost:8080 helloworld.Greeter/SayHello ``` ```Shell ./target/maven-jlink/default/bin/java --add-modules io.netty.resolver.dns.classes.macos,io.netty.resolver.dns.macos.osx.aarch_64 --module jpms.examples/io.vertx.example.jpms.grpc.Server ``` -------------------------------- ### Run Vert.x Shell Service via HTTP Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc This example shows how to run the Vert.x Shell service accessible via HTTP as a packaged Vert.x service. After running, point your browser to the specified URL and type 'help' within the shell to see available commands. ```Shell http://localhost:8080/shell.html ``` -------------------------------- ### Test and Run Vert.x HTTP Compression Server with JPMS Source: https://github.com/vert-x3/vertx-examples/blob/5.x/jpms-examples/README.adoc An HTTP/1.1 server example demonstrating Brotli compression with Vert.x and JPMS. This snippet provides commands to test the server's compression capabilities using `curl` and `brotli`, and also shows how to run the server as a jlink application image for Mac/M1. ```Shell curl -sH 'Accept-encoding: br' http://localhost:8080 | brotli -c -d ``` ```Shell ./target/maven-jlink/default/bin/java --add-modules io.netty.resolver.dns.classes.macos,io.netty.resolver.dns.macos.osx.aarch_64 --module jpms.examples/io.vertx.example.jpms.compression.Server ``` -------------------------------- ### Querying the Vert.x Gateway Service Source: https://github.com/vert-x3/vertx-examples/blob/5.x/zipkin-examples/README.adoc Demonstrates how to query the Gateway, a simple HTTP gateway exposing both Joke and Hello services, using curl. This service contributes traces from its HTTP server and HTTP client. ```bash > curl http://localhost:8080/hello > curl http://localhost:8080/joke ``` -------------------------------- ### Create Echo Keyboard Custom Shell Command Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc This example prints on the screen whatever the user types on their keyboard, showing how a command can capture keyboard events. After running the shell, connect via Telnet and execute 'echokeyboard'. Type some text, then press Ctrl-C to quit. ```Shell telnet localhost 3000 echokeyboard ``` -------------------------------- ### Build and Run Vert.x Kotlin Application as Far Jar Source: https://github.com/vert-x3/vertx-examples/blob/5.x/kotlin-coroutines-examples/README.md Instructions to package the Vert.x Kotlin application into an executable JAR file using Maven and then run it from the command line. ```Shell mvn package java -jar target/service.jar ``` -------------------------------- ### Vert.x RxJava2 Web Client: Simple Request Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-2-examples/README.adoc This example demonstrates a basic web client. It creates a `Single>` and then allows multiple subscriptions to this single to send the HTTP request, showcasing fundamental web client usage with RxJava. ```Java src/main/java/io/vertx/example/reactivex/web/client/simple/Client.java ``` -------------------------------- ### Query Hello Service via cURL Source: https://github.com/vert-x3/vertx-examples/blob/5.x/opentelemetry-examples/README.adoc Demonstrates how to query the Hello microservice, which says hello and utilizes the Joke service, using cURL. This service contributes traces from its HTTP server and client interactions. ```shell curl http://localhost:8081 ``` -------------------------------- ### Run Vert.x Shell Service via Telnet Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc This example shows how to run the Vert.x Shell service accessible via Telnet as a packaged Vert.x service. After running, connect using Telnet and type 'help' to see available commands. ```Shell telnet localhost 3000 help ``` -------------------------------- ### Simple HTTP/2 Client Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Demonstrates a basic HTTP/2 client making a request to a server. This client is designed for simple communication over HTTP/2. ```Java src/main/java/io/vertx/example/core/http2/simple/Client.java ``` -------------------------------- ### API: Get Movie Details by ID Source: https://github.com/vert-x3/vertx-examples/blob/5.x/kotlin-coroutines-examples/README.md Demonstrates how to retrieve details for a specific movie (e.g., 'starwars') using a GET request to the REST API. The response includes the movie's ID and title. ```Shell curl http://localhost:8080/movie/starwars ``` -------------------------------- ### Create Top Custom Shell Command Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc This example displays a list of current JVM threads, mimicking the OS 'top' command. It demonstrates how to periodically push data to the Shell. After running the shell, connect via Telnet and execute 'top'. Press Ctrl-C to quit. ```Shell telnet localhost 3000 top ``` -------------------------------- ### Send Multiple Requests to Vert.x HTTP Server Source: https://github.com/vert-x3/vertx-examples/blob/5.x/spring-examples/spring-verticle-factory/README.adoc Send ten sequential HTTP GET requests to the local Vert.x server to observe how different event loops handle the incoming traffic. ```shell seq 10 | while read i; do curl http://localhost:8080/?name=Thomas${i}; echo; done ``` -------------------------------- ### Querying the Vert.x Joke Service Source: https://github.com/vert-x3/vertx-examples/blob/5.x/zipkin-examples/README.adoc Demonstrates how to query the Joke service, an HTTP microservice providing jokes from PostgreSQL, using curl. This service contributes traces from its HTTP server and database client. ```bash > curl http://localhost:8082 ``` -------------------------------- ### Interact with SQL Client REST API using cURL Source: https://github.com/vert-x3/vertx-examples/blob/5.x/web-examples/README.adoc Examples demonstrating how to interact with the Vert.x SQL Client REST API using cURL commands for retrieving all products, accessing a specific product by name, and creating a new product via a POST request with JSON payload. ```curl curl http://localhost:8080/products curl http://localhost:8080/products/Spatula curl -X POST -H "Content-Type: application/json" -d '{"name":"Spoon","price":1.0,"weight":1.0}' http://localhost:8080/products ``` -------------------------------- ### Vert.x Future API Usage Examples Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc This entry points to a collection of examples demonstrating the use of Vert.x Futures. Futures are used for asynchronous programming, representing the result of an asynchronous operation. ```Java src/main/java/io/vertx/example/core/future ``` -------------------------------- ### Run Vert.x HTTP/1.1 Server with JPMS Source: https://github.com/vert-x3/vertx-examples/blob/5.x/jpms-examples/README.adoc A simple HTTP/1.1 server example using Vert.x with JPMS. This snippet shows how to run the server as a jlink application image, specifically for Mac/M1 architectures. The server can be tested by curling `http://localhost:8080`. ```Shell ./target/maven-jlink/default/bin/java --add-modules io.netty.resolver.dns.classes.macos,io.netty.resolver.dns.macos.osx.aarch_64 --module jpms.examples/io.vertx.example.jpms.http.Server ``` -------------------------------- ### Interact with Movie Rating REST API using cURL Source: https://github.com/vert-x3/vertx-examples/blob/5.x/virtual-threads-examples/README.adoc Demonstrates how to interact with the Vert.x movie rating REST application using cURL commands to retrieve movie details, get current ratings, and submit new ratings. ```Shell > curl http://localhost:8080/movie/starwars {"id":"starwars","title":"Star Wars"} ``` ```Shell > curl http://localhost:8080/getRating/indianajones {"id":"indianajones","rating":5} ``` ```Shell > curl -X POST http://localhost:8080/rateMovie/starwars?rating=4 ``` -------------------------------- ### HTTP/2 Clear Text (h2c) Client Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Demonstrates an HTTP client connecting to an h2c server, communicating over HTTP/2 without TLS. Note that this example may not work with standard browsers. ```Java src/main/java/io/vertx/example/core/http2/h2c/Client.java ``` -------------------------------- ### Accessing gRPC Transcoding Service with cURL Source: https://github.com/vert-x3/vertx-examples/blob/5.x/grpc-examples/README.adoc This shell command demonstrates how to access a gRPC service transcoded as a REST endpoint using a simple HTTP client. It sends a GET request with JSON content type to the `/v1/hello/Julien` endpoint and expects a JSON response, illustrating the successful transcoding. ```Shell > curl -H 'Content-Type: application/json' http://localhost:8080/v1/hello/Julien { "message": "Julien" } ``` -------------------------------- ### API: Get Movie Rating by ID Source: https://github.com/vert-x3/vertx-examples/blob/5.x/kotlin-coroutines-examples/README.md Demonstrates how to retrieve the current rating for a specific movie (e.g., 'indianajones') using a GET request to the REST API. The response includes the movie's ID and its rating. ```Shell curl http://localhost:8080/getRating/indianajones ``` -------------------------------- ### HTTP/2 Custom Frames Client Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Shows an HTTP client capable of sending and receiving custom HTTP/2 frames. This example complements the custom frames server, demonstrating full custom frame communication. ```Java src/main/java/io/vertx/example/core/http2/customframes/Client.java ``` -------------------------------- ### Vert.x Verticle Deployment Patterns Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Demonstrates various ways to deploy and undeploy Vert.x verticles. This includes asynchronous deployment, waiting for deployment completion, passing configuration, deploying multiple instances, deploying as worker verticles, and explicit undeployment. ```Java src ``` -------------------------------- ### Create Wget Custom Shell Command Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc This example uses the Vert.x HTTP client to create a simple version of the 'wget' command. It illustrates how a custom command can interact with other Vert.x APIs, specifically the HttpClient. After running the shell, connect via Telnet and execute 'wget ' to fetch content. ```Shell telnet localhost 3000 wget ``` -------------------------------- ### Launch Vert.x Server with Netty Native Transports via JVM Arguments Source: https://github.com/vert-x3/vertx-examples/blob/5.x/jpms-examples/README.adoc This shell command illustrates how to run a Vert.x server with Netty native transports (kqueue) by adding the required modules directly to the JVM launch command, along with DNS resolver modules for macOS. ```shell ./target/maven-jlink/default/bin/java --add-modules io.netty.resolver.dns.classes.macos,io.netty.resolver.dns.macos.osx.aarch_64,io.netty.transport.classes.kqueue,io.netty.transport.kqueue.osx.aarch_64 --module jpms.examples/io.vertx.example.jpms.native_transport.Server ``` -------------------------------- ### Query Gateway Service Endpoints via cURL Source: https://github.com/vert-x3/vertx-examples/blob/5.x/opentelemetry-examples/README.adoc Demonstrates how to query the Gateway, a simple HTTP gateway exposing both Joke and Hello services, using cURL. The gateway's HTTP server and client contribute traces. ```shell curl http://localhost:8080/hello curl http://localhost:8080/joke ``` -------------------------------- ### Run Node.js Client for Vert.x Service Proxy Source: https://github.com/vert-x3/vertx-examples/blob/5.x/service-proxy-examples/service-provider/README.md Executes the Node.js client application to interact with the Vert.x service proxy server. Ensure the Vert.x server component is running before executing this command. ```Shell node index.js ``` -------------------------------- ### Vert.x RxJava2 Event Bus: Ping/Pong Messaging Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-2-examples/README.adoc An example demonstrating a simple ping-pong message exchange over the Vert.x event bus using the RxJava API. It illustrates the process of sending, receiving, and replying to messages in a reactive manner. ```Java src/main/java/io/vertx/example/reactivex/eventbus/pingpong/PingPong.java ``` -------------------------------- ### Run Vert.x HTTP/2 Server with JPMS Source: https://github.com/vert-x3/vertx-examples/blob/5.x/jpms-examples/README.adoc A simple HTTP/2 server example using Vert.x with JPMS. This snippet demonstrates how to run the server as a jlink application image, particularly for Mac/M1 systems. The server can be tested by curling `https://localhost:8443` with the `-k` flag for insecure connections. ```Shell ./target/maven-jlink/default/bin/java --add-modules io.netty.resolver.dns.classes.macos,io.netty.resolver.dns.macos.osx.aarch_64 --module jpms.examples/io.vertx.example.jpms.http2.Server ``` -------------------------------- ### Run Vert.x Shell Term Caster via Telnet Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc Instructions to connect to the Vert.x Shell term server via telnet to broadcast the current host screen to the client. This example uses TermServer, which provides simple terminal capabilities and grants the handler total control until Ctrl-C is hit. ```Bash telnet localhost 3000 ``` -------------------------------- ### Vert.x RxJava2 Event Bus: Publish/Subscribe Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-2-examples/README.adoc This example reinterprets the core Vert.x event bus publish/subscribe pattern using the RxJava API. It showcases how subscribers can leverage RxJava for reactive message consumption, providing a modern approach to event-driven communication. ```Java src/main/java/io/vertx/example/reactivex/eventbus/pubsub/Receiver.java ``` ```Java src/main/java/io/vertx/example/reactivex/eventbus/pubsub/Sender.java ``` -------------------------------- ### Vert.x RxJava2 Web Client: JSON Unmarshalling Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-2-examples/README.adoc This example focuses on the web client's unmarshalling capabilities. It demonstrates how a JSON response from the web client can be automatically unmarshalled into a Java object, simplifying data processing. ```Java src/main/java/io/vertx/example/reactivex/web/client/unmarshalling/Client.java ``` -------------------------------- ### Basic Vert.x Template with Arguments and Imports Source: https://github.com/vert-x3/vertx-examples/blob/5.x/web-examples/src/main/resources/io/vertx/example/web/templating/rocker/templates/index.rocker.html This snippet showcases a fundamental Vert.x template. It begins by importing a Java class (`io.vertx.ext.web.RoutingContext`), defines input arguments (`title`, `name`, `path`) that the template expects, and then uses these arguments to render personalized content within the template's body. It also demonstrates calling another template (`@templates.main.template(title)`). ```Vert.x Template @import io.vertx.ext.web.RoutingContext @args (String title, String name, String path) @templates.main.template(title) -> { Hello @name! Request path is @path } ``` -------------------------------- ### Vert.x-Web Product Catalogue REST API Endpoints Source: https://github.com/vert-x3/vertx-examples/blob/5.x/web-examples/README.adoc API endpoints for a simple product catalogue microservice built with Vert.x-Web, supporting operations to list all products, retrieve a specific product by ID, and add a new product. ```APIDOC List all products: GET /products Get a product: GET /products/ Add a product: PUT /products/ ``` -------------------------------- ### Enable JMX for Vert.x Metrics Source: https://github.com/vert-x3/vertx-examples/blob/5.x/metrics-examples/README.adoc Append these command-line options when running a Vert.x application to enable JMX. This allows Vert.x metrics to be monitored via JMX explorers like JConsole under the 'vertx' domain. ```Shell -Dvertx.metrics.options.jmxEnabled=true -Dvertx.metrics.options.jmxDomain=vertx ``` -------------------------------- ### Launch Vert.x Server with Netty OpenSSL via JVM Arguments Source: https://github.com/vert-x3/vertx-examples/blob/5.x/jpms-examples/README.adoc This shell command demonstrates how to run a Vert.x server utilizing Netty OpenSSL by adding the necessary tcnative modules directly to the JVM launch command, alongside DNS resolver modules for macOS. ```shell ./target/maven-jlink/default/bin/java --add-modules io.netty.resolver.dns.classes.macos,io.netty.resolver.dns.macos.osx.aarch_64,io.netty.tcnative.classes.openssl,io.netty.internal.tcnative.openssl.osx.aarch_64 --module jpms.examples/io.vertx.example.jpms.openssl.Server ``` -------------------------------- ### Run Vert.x Shell Service via SSH Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc This example shows how to run the Vert.x Shell service accessible via SSH as a packaged Vert.x service. After running, connect using SSH and type 'help' to see available commands. The default password for 'admin' is 'password'. ```Shell ssh -p 3000 admin@localhost help ``` -------------------------------- ### HTTP/2 Push-Aware Client Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Demonstrates an HTTP client capable of handling server-side HTTP/2 pushes. The client sets a push handler to receive notifications and process pushed resources. ```Java src/main/java/io/vertx/example/core/http2/push/Client.java ``` -------------------------------- ### Deploy Vert.x Shell Service via SSH Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc This example shows how to deploy the Vert.x Shell service accessible via SSH as a packaged Vert.x service. The SSH connector is configured to use 'keystore.jks' for SSH key pairs and 'auth.properties' for user authentication. The service is deployed using the 'service:io.vertx.ext.shell' deployment name. After deployment, connect using SSH and type 'help' to see available commands. The default password for 'admin' is 'password'. ```Shell ssh -p 3000 admin@localhost help ``` -------------------------------- ### Vert.x-Web Maven/Gradle Dependencies Source: https://github.com/vert-x3/vertx-examples/blob/5.x/web-examples/README.adoc Required dependencies for including Vert.x-Web in Maven or Gradle projects. Core Vert.x and Vert.x-Web modules are essential, with additional template engine dependencies needed if applicable. ```Plaintext Group ID: io.vertx Artifact ID: vertx-core Group ID: io.vertx Artifact ID: vertx-web ``` -------------------------------- ### Query Joke Service via cURL Source: https://github.com/vert-x3/vertx-examples/blob/5.x/opentelemetry-examples/README.adoc Demonstrates how to query the Joke microservice, which provides jokes stored in PostgreSQL, using cURL. This service contributes traces for its HTTP server and database client interactions. ```shell curl http://localhost:8082 ``` -------------------------------- ### HTTP/2 Custom Frames Server Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Illustrates an HTTP/2 server that can send and receive custom HTTP/2 frames. This demonstrates extending the HTTP/2 protocol for specific application needs. ```Java src/main/java/io/vertx/example/core/http2/customframes/Server.java ``` -------------------------------- ### Vert.x RxJava2 Real-time Web: SockJS Integration Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-2-examples/README.adoc This example illustrates how an RxJava `Flowable` source can be sent in real-time to a browser via a `SockJSSocket`. It covers both the server-side logic, where a `Flowable` (e.g., from EventBus) is subscribed to and observed items are sent, and the client-side JavaScript for receiving and displaying messages, ideal for responsive web applications. ```Java src/main/java/io/vertx/example/reactivex/web/realtime/Server.java ``` ```HTML src/main/resources/webroot/index.html ``` -------------------------------- ### Vert.x Non-Blocking Execution with Blocking Code Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Demonstrates how to safely execute blocking code within a Vert.x application without blocking the event loop. This includes a general `executeBlocking` example and another showing the use of a dedicated worker pool for specific blocking tasks. ```Java src/main/java/io/vertx/example/core/execblocking/ExecBlockingExample.java ``` ```Java src/main/java/io/vertx/example/core/execblocking/ExecBlockingDedicatedPoolExample.java ``` -------------------------------- ### Vert.x RxJava2 HTTP Client: JSON Unmarshalling Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-2-examples/README.adoc This example demonstrates how to unmarshall JSON responses from an HTTP client into Java objects. It specifically highlights the use of `RxHelper.unmarshaller` as a Rx operator applied to the response via the `lift` method, streamlining JSON parsing. ```Java src/main/java/io/vertx/example/reactivex/http/client/unmarshalling/Client.java ``` -------------------------------- ### Vert.x Non-Blocking JSON Streaming Parser Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc A simple example showcasing the use of Vert.x's streaming `JsonParser` to efficiently parse large JSON arrays containing numerous small objects in a non-blocking manner, ideal for handling big data streams. ```Java src/main/java/io/vertx/example/core/jsonstreaming/JsonStreamingExample.java ``` -------------------------------- ### Vert.x Worker Verticle Usage and Thread Switching Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Illustrates the creation and interaction with Vert.x worker verticles. Worker verticles operate off the event loop, allowing them to perform blocking operations without impacting responsiveness. The example highlights how thread context switches when interacting with these verticles. ```Java src/main/java/io/vertx/example/core/verticle/worker/MainVerticle.java ``` ```Java src/main/java/io/vertx/example/core/verticle/worker/WorkerVerticle.java ``` -------------------------------- ### Vert.x RxJava2 HTTP Client: Response Reduction Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-2-examples/README.adoc Building on the simple HTTP client, this example demonstrates advanced operations on the response `Flowable`. It uses `flatMap` to transform the response, `reduce` to merge all buffers into a single one, and `map` to convert the final buffer to a string before the `subscribe` delivers the content. ```Java src/main/java/io/vertx/example/reactivex/http/client/reduce/Client.java ``` -------------------------------- ### Create Starwars Ascii Stream Custom Shell Command Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc This example uses the Vert.x NetClient to stream the content of a Starwars ASCII movie into the Shell until Ctrl-C is pressed. When executed, the command connects to a remote Telnet server that broadcasts an ASCII Starwars movie. After running the shell, connect via Telnet and execute 'starwars'. Press Ctrl-C to quit. ```Shell telnet localhost 3000 starwars ``` -------------------------------- ### Connect to Real-time News Feed with SockJS Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-3-examples/src/main/resources/webroot/index.html This JavaScript code establishes a WebSocket-like connection to a news feed server using the SockJS library. It sets up an 'onmessage' event handler to process incoming data, wrapping it in `` tags and prepending it to an HTML element with the ID 'status', effectively displaying real-time updates. ```JavaScript var sock = new SockJS('http://localhost:8080/news-feed'); sock.onmessage = function(e) { var str = "" + e.data + "
"; $('#status').prepend(str); }; ``` -------------------------------- ### Vert.x RxJava2 Web Client: Zipping Multiple Requests Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-2-examples/README.adoc A variation of the simple web client example, this snippet shows how to map two client requests to an `Single` and then 'zip' them into a single JSON object. The primary goal is to illustrate how to combine results from multiple asynchronous web client responses. ```Java src/main/java/io/vertx/example/reactivex/web/client/zip/Client.java ``` -------------------------------- ### Vert.x Event Bus Publish/Subscribe Receiver Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Demonstrates a Vert.x Event Bus receiver participating in a publish/subscribe pattern. It listens on an address and logs all messages published to it, allowing multiple subscribers to receive the same message. ```Java src/main/java/io/vertx/example/core/eventbus/pubsub/Receiver.java ``` -------------------------------- ### API Documentation for Movie Rating Service Source: https://github.com/vert-x3/vertx-examples/blob/5.x/kotlin-coroutines-examples/README.md Detailed documentation for the REST API endpoints exposed by the Vert.x Kotlin movie rating application, including methods, parameters, and expected responses. ```APIDOC Endpoint: GET /movie/{id} Description: Retrieves details for a specific movie. Parameters: id (string): The unique identifier of the movie. Response: 200 OK: Content: application/json Schema: id (string): The movie's ID. title (string): The movie's title. Endpoint: GET /getRating/{id} Description: Retrieves the current rating for a specific movie. Parameters: id (string): The unique identifier of the movie. Response: 200 OK: Content: application/json Schema: id (string): The movie's ID. rating (number): The current rating of the movie. Endpoint: POST /rateMovie/{id}?rating={value} Description: Submits a rating for a specific movie. Parameters: id (string): The unique identifier of the movie. rating (number): The rating value to assign to the movie. Response: 200 OK: No content. ``` -------------------------------- ### Vert.x RxJava2 HTTP Client: Zipping Multiple Requests Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-2-examples/README.adoc Similar to the web client's zip example, this snippet shows how to combine results from two HTTP client requests. It maps requests to an `Flowable` and then 'zips' them into a single JSON object, useful for scenarios requiring aggregated data from multiple HTTP calls. ```Java src/main/java/io/vertx/example/reactivex/http/client/zip/Client.java ``` -------------------------------- ### Vert.x Event Bus Publish/Subscribe Sender Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Illustrates a Vert.x Event Bus sender for publish/subscribe messaging. It periodically publishes messages to an address, which are then received by all subscribed receivers. ```Java src/main/java/io/vertx/example/core/eventbus/pubsub/Sender.java ``` -------------------------------- ### Client-Side SockJS News Feed Consumer Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-2-examples/src/main/resources/webroot/index.html This JavaScript snippet initializes a SockJS connection to a news feed endpoint and appends incoming messages to an HTML element with the ID 'status'. It demonstrates basic real-time message consumption in a web browser. ```JavaScript var sock = new SockJS('http://localhost:8080/news-feed'); sock.onmessage = function(e) { var str = "" + e.data + "
"; $('#status').prepend(str); }; ``` -------------------------------- ### Vert.x Event Bus Point-to-Point Sender Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Illustrates a Vert.x Event Bus sender for point-to-point communication. It sends messages to a specific address periodically and logs replies received from the receiver. ```Java src/main/java/io/vertx/example/core/eventbus/pointtopoint/Sender.java ``` -------------------------------- ### Vert.x Event Bus Point-to-Point Receiver Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Demonstrates a Vert.x Event Bus receiver configured for point-to-point messaging. It listens on a specific address, processes incoming messages, and sends replies back to the sender. ```Java src/main/java/io/vertx/example/core/eventbus/pointtopoint/Receiver.java ``` -------------------------------- ### Create Vert.x Service Proxy for Consumer Source: https://github.com/vert-x3/vertx-examples/blob/5.x/service-proxy-examples/README.adoc On the consumer side, this code demonstrates how to obtain a proxy for a registered Vert.x service. By calling `ProcessorService.createProxy`, a client-side proxy is generated that allows invoking the remote service methods as if they were local, using the specified event bus address. ```Java ProcessorService service = ProcessorService.createProxy(vertx, "vertx.processor"); ``` -------------------------------- ### Perform Cross-Site XMLHttpRequest with Access Control (GET) Source: https://github.com/vert-x3/vertx-examples/blob/5.x/web-examples/src/main/resources/io/vertx/example/web/cors/webroot/nopreflight.html This JavaScript snippet demonstrates how to make a simple cross-site XMLHttpRequest (XHR) using an HTTP GET request to a different domain. It relies on Access Control (CORS) to mitigate security concerns and is designed for scenarios that do not require a preflight request. The snippet fetches content from 'http://localhost:8080/access-control-with-get/' and appends it to an element with ID 'textDiv'. ```JavaScript var url = 'http://localhost:8080/access-control-with-get/'; function callOtherDomain() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var e = document.createElement('p'); e.innerHTML = xhttp.responseText; document.getElementById("textDiv").appendChild(e); } else { console.log("XMLHttpRequest readyState:" + this.readyState + " status: " + this.status); } }; xhttp.open("GET", url, true); xhttp.send(); } ``` -------------------------------- ### JavaScript WebSocket Connection and Event Handling Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/src/main/resources/io/vertx/example/core/http/websockets/ws.html This snippet initializes a WebSocket connection to a specified URL. It sets up event handlers for 'onmessage' to receive data, 'onopen' for successful connection, and 'onclose' for connection termination. It also includes a browser compatibility check for WebSockets, alerting the user if not supported. ```JavaScript var socket; if (window.WebSocket) { socket = new WebSocket("ws://localhost:8080/myapp"); socket.onmessage = function (event) { alert("Received data from websocket: " + event.data); } socket.onopen = function (event) { alert("Web Socket opened!"); }; socket.onclose = function (event) { alert("Web Socket closed."); }; } else { alert("Your browser does not support Websockets. (Use Chrome)"); } ``` -------------------------------- ### Vert.x RxJava2 HTTP: Simple Server and Client Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-2-examples/README.adoc This snippet presents a basic HTTP server and client implementation. The server uses an `Flowable` to handle incoming requests, while the client utilizes an `Flowable` and applies `flatMap` to process the response as a `Flowable`. ```Java src/main/java/io/vertx/example/reactivex/http/client/simple/Server.java ``` ```Java src/main/java/io/vertx/example/reactivex/http/client/simple/Client.java ``` -------------------------------- ### Vert.x Event Bus SSL Receiver Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Demonstrates a Vert.x Event Bus receiver configured for point-to-point messaging with transport-level SSL encryption. It securely listens for messages and replies to them. ```Java src/main/java/io/vertx/example/core/eventbus/ssl/Receiver.java ``` -------------------------------- ### Register Vert.x Service Handler Directly Source: https://github.com/vert-x3/vertx-examples/blob/5.x/service-proxy-examples/README.adoc As an alternative to `ServiceBinder`, this snippet shows how to directly instantiate and register the generated `ProcessorServiceVertxProxyHandler`. This method requires the proxy handler classes to be pre-generated, typically via a manual `mvn compile` step, before runtime registration. ```Java new ProcessorServiceVertxProxyHandler(vertx, service).registerHandler("vertx.processor"); ``` -------------------------------- ### Run Vert.x JPMS gRPC Server with Protobuf Check Disabled Source: https://github.com/vert-x3/vertx-examples/blob/5.x/jpms-examples/README.adoc This snippet shows how to launch a Vert.x gRPC server using JPMS, specifically addressing a dependency requirement by temporarily disabling a Protobuf version check and adding necessary Netty modules for macOS. ```shell export TEMPORARILY_DISABLE_PROTOBUF_VERSION_CHECK=true ./target/maven-jlink/default/bin/java --add-modules io.netty.resolver.dns.classes.macos,io.netty.resolver.dns.macos.osx.aarch_64 --module jpms.examples/io.vertx.example.jpms.grpc.Server ``` -------------------------------- ### JavaScript Client for Vert.x EventBus News Feed Subscription Source: https://github.com/vert-x3/vertx-examples/blob/5.x/web-examples/src/main/resources/io/vertx/example/web/realtime/webroot/index.html This JavaScript code initializes a Vert.x EventBus client to connect to a server-side event bus. Once connected, it registers a handler for the 'news-feed' address. Incoming messages are then formatted and prepended to an HTML element with the ID 'status', effectively displaying real-time news updates. ```JavaScript var eb = new EventBus("http://localhost:8080/eventbus"); eb.onopen = function () { eb.registerHandler("news-feed", function (err, msg) { var str = "" + msg.body + "
"; $('#status').prepend(str); }) } ``` -------------------------------- ### Observe Vert.x Event Loop Distribution in Console Source: https://github.com/vert-x3/vertx-examples/blob/5.x/spring-examples/spring-verticle-factory/README.adoc Review the console output to confirm that incoming HTTP requests are processed by distinct Vert.x event loop threads, illustrating the Multi-Reactor pattern in action. ```Console Output 12:46:02.661 [*vert.x-eventloop-thread-2*] INFO io.vertx.examples.spring.verticlefactory.GreetingVerticle - Got request for name: Thomas1 12:46:02.685 [*vert.x-eventloop-thread-4*] INFO io.vertx.examples.spring.verticlefactory.GreetingVerticle - Got request for name: Thomas2 12:46:02.698 [*vert.x-eventloop-thread-1*] INFO io.vertx.examples.spring.verticlefactory.GreetingVerticle - Got request for name: Thomas3 12:46:02.711 [*vert.x-eventloop-thread-3*] INFO io.vertx.examples.spring.verticlefactory.GreetingVerticle - Got request for name: Thomas4 12:46:02.722 [*vert.x-eventloop-thread-2*] INFO io.vertx.examples.spring.verticlefactory.GreetingVerticle - Got request for name: Thomas5 12:46:02.733 [*vert.x-eventloop-thread-4*] INFO io.vertx.examples.spring.verticlefactory.GreetingVerticle - Got request for name: Thomas6 12:46:02.748 [*vert.x-eventloop-thread-1*] INFO io.vertx.examples.spring.verticlefactory.GreetingVerticle - Got request for name: Thomas7 12:46:02.761 [*vert.x-eventloop-thread-3*] INFO io.vertx.examples.spring.verticlefactory.GreetingVerticle - Got request for name: Thomas8 12:46:02.773 [*vert.x-eventloop-thread-2*] INFO io.vertx.examples.spring.verticlefactory.GreetingVerticle - Got request for name: Thomas9 12:46:02.785 [*vert.x-eventloop-thread-4*] INFO io.vertx.examples.spring.verticlefactory.GreetingVerticle - Got request for name: Thomas10 ``` -------------------------------- ### Add Netty Native Transport Modules to module-info.java Source: https://github.com/vert-x3/vertx-examples/blob/5.x/jpms-examples/README.adoc This Java snippet demonstrates how to declare required Netty native transport modules (kqueue for macOS AArch64) within a module-info.java file for a Vert.x application, enabling optimized I/O. ```java // Add to module-info.java requires io.netty.transport.classes.kqueue; requires io.netty.transport.kqueue.osx.aarch_64; ``` -------------------------------- ### Vert.x gRPC Maven/Gradle Dependency Source: https://github.com/vert-x3/vertx-examples/blob/5.x/grpc-examples/README.adoc Add this dependency to your Maven or Gradle project to use Vert.x gRPC. It specifies the group ID and artifact ID for the Vert.x gRPC library. You will also need the com.google.protobuf plugin and io.vertx:vertx-grpc-protoc-plugin for .proto file compilation. ```Maven/Gradle Group ID: io.vertx Artifact ID: vertx-grpc ``` -------------------------------- ### Add Netty OpenSSL Modules to module-info.java Source: https://github.com/vert-x3/vertx-examples/blob/5.x/jpms-examples/README.adoc This Java snippet shows how to include Netty's OpenSSL (tcnative) modules for macOS AArch64 in a module-info.java file, enabling secure communication with optimized SSL/TLS performance in a Vert.x application. ```java // Add to module-info.java requires io.netty.tcnative.classes.openssl; requires io.netty.internal.tcnative.openssl.osx.aarch_64; ``` -------------------------------- ### Vert.x Event Bus SSL Sender Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Illustrates a Vert.x Event Bus sender for point-to-point communication with SSL encryption. It securely sends messages and logs replies, ensuring data integrity and confidentiality. ```Java src/main/java/io/vertx/example/core/eventbus/ssl/Sender.java ``` -------------------------------- ### Configure Jolokia JVM Agent for JMX REST Exposure Source: https://github.com/vert-x3/vertx-examples/blob/5.x/metrics-examples/README.adoc Set the JAVA_OPTS environment variable to include the Jolokia JVM agent. This configuration exposes JMX metrics as a REST interface, specifying the agent JAR path, port, and host for access. ```Shell export JAVA_OPTS="-javaagent:path/to/jolokia-jvm-x.x.x-agent.jar=port=7777,host=localhost" ``` -------------------------------- ### Register Vert.x Service Using ServiceBinder Source: https://github.com/vert-x3/vertx-examples/blob/5.x/service-proxy-examples/README.adoc This code illustrates the recommended way to register a Vert.x service on the event bus using the `ServiceBinder` utility. It sets the event bus address and associates the service interface (`ProcessorService.class`) with its implementation instance (`service`), making it discoverable by consumers. ```Java new ServiceBinder(vertx) .setAddress("vertx.processor") .register(ProcessorService.class, service); ``` -------------------------------- ### HTTP/2 Clear Text (h2c) Server Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Shows an HTTP/2 server operating in clear text mode (h2c), without TLS encryption. This is similar to the simple HTTP/2 server but without the security layer. ```Java src/main/java/io/vertx/example/core/http2/h2c/Server.java ``` -------------------------------- ### API: Rate a Movie Source: https://github.com/vert-x3/vertx-examples/blob/5.x/kotlin-coroutines-examples/README.md Demonstrates how to submit a new rating for a movie (e.g., 'starwars' with a rating of 4) using a POST request to the REST API. This operation updates the movie's rating. ```Shell curl -X POST http://localhost:8080/rateMovie/starwars?rating=4 ``` -------------------------------- ### Process Document with Vert.x EventBus in JavaScript Source: https://github.com/vert-x3/vertx-examples/blob/5.x/service-proxy-examples/service-provider/src/main/resources/webroot/index.html This JavaScript code connects to a Vert.x EventBus, initializes a ProcessorService proxy, and calls its 'process' method with a document name. It retrieves the document name from the URL query string or defaults to 'order', then displays the processing result or an error on the webpage. ```JavaScript var eb = new EventBus("http://localhost:8080/eventbus"); eb.onopen = function() { var processorService = new ProcessorService(eb, "vertx.processor"); var name = getQueryVariable("document_name"); if (name == null) { name = 'order'; } processorService.process({name: name}, function (err, res) { if (err) { document.getElementById('result').innerHTML = 'ERROR: ' + JSON.stringify(err); return; } document.getElementById('result').innerHTML = 'RESULT: ' + JSON.stringify(res); }); }; function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); if (decodeURIComponent(pair[0]) == variable) { return decodeURIComponent(pair[1]); } } console.log('Query variable %s not found', variable); } ``` -------------------------------- ### Run Vert.x Shell Starwars Command via Telnet Source: https://github.com/vert-x3/vertx-examples/blob/5.x/shell-examples/README.adoc Instructions to run the Vert.x Shell in an IDE and then connect using telnet to execute the 'starwars' command. The command handles Ctrl-C (EventType.SIGINT) to close the socket and terminate, allowing the shell to regain control. ```Bash telnet localhost 3000 starwars ``` -------------------------------- ### Configure Vert.x Redis Client Host Source: https://github.com/vert-x3/vertx-examples/blob/5.x/redis-examples/README.adoc This JSON snippet shows how to configure the host for the Vert.x Redis Client. By default, the host is '127.0.0.1' and the port is '6379'. This configuration is used when deploying verticles. ```JSON { "host": "192.168.59.103" } ``` -------------------------------- ### Vert.x Event Bus Cluster-Wide MessageCodec Receiver Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Shows a Vert.x Event Bus receiver for custom messages, designed to operate in a clustered environment. It demonstrates how a custom MessageCodec enables sending and receiving custom types across the cluster. ```Java src/main/java/io/vertx/example/core/eventbus/messagecodec/ClusterReceiver.java ``` -------------------------------- ### Define News Feed CSS Styling Source: https://github.com/vert-x3/vertx-examples/blob/5.x/rxjava-3-examples/src/main/resources/webroot/index.html This CSS snippet defines a basic style rule for elements with the class 'news', setting their font size to 20 points. This is typically used for visual presentation of news items. ```CSS .news { font-size: 20pt; } ``` -------------------------------- ### Vert.x Event Bus Custom MessageCodec Sender Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Demonstrates sending custom data types over the Vert.x Event Bus using a custom MessageCodec. This sender interacts with both local and cluster-wide receivers to show codec behavior. ```Java src/main/java/io/vertx/example/core/eventbus/messagecodec/Sender.java ``` -------------------------------- ### Display Client-Side Cookie Value with jQuery Source: https://github.com/vert-x3/vertx-examples/blob/5.x/web-examples/src/main/resources/io/vertx/example/web/cookie/webroot/index.html This JavaScript snippet, executed when the DOM is ready, retrieves the value of a cookie named 'visits' using jQuery's cookie plugin and displays it within an HTML element identified by 'totalTimes'. ```JavaScript $(document).ready(function () { $('#totalTimes').html($.cookie('visits')); }); ``` -------------------------------- ### Vert.x Event Bus Local MessageCodec Receiver Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Illustrates a Vert.x Event Bus receiver for custom messages, deployed locally from the sender. It processes custom data types received via the Event Bus using a registered MessageCodec. ```Java src/main/java/io/vertx/example/core/eventbus/messagecodec/LocalReceiver.java ``` -------------------------------- ### Handle Service Result in Vert.x Processor Service Implementation Source: https://github.com/vert-x3/vertx-examples/blob/5.x/service-proxy-examples/README.adoc This snippet demonstrates how a Vert.x service implementation should handle the result of an operation. It shows the standard pattern of invoking the `resultHandler` with a `Future.succeededFuture` containing the processed result, indicating successful completion of the service method. ```Java resultHandler.handle(Future.succeededFuture(result)); ``` -------------------------------- ### Vert.x Event Bus Custom MessageCodec Implementation Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/README.adoc Provides the implementation of a custom MessageCodec for the Vert.x Event Bus. This codec defines how custom data types are encoded and decoded for transmission over the event bus, enabling their use beyond primitive types. ```Java src/main/java/io/vertx/example/core/eventbus/messagecodec/util/CustomMessageCodec.java ``` -------------------------------- ### CSS Styling for News Feed Display Source: https://github.com/vert-x3/vertx-examples/blob/5.x/web-examples/src/main/resources/io/vertx/example/web/realtime/webroot/index.html This CSS snippet defines a style rule for elements with the class 'news', setting their font size to 20 points. This is typically used to format the appearance of news items on a web page. ```CSS .news { font-size: 20pt; } ``` -------------------------------- ### JavaScript Function to Send WebSocket Messages Source: https://github.com/vert-x3/vertx-examples/blob/5.x/core-examples/src/main/resources/io/vertx/example/core/http/websockets/ws.html This function sends a message over an established WebSocket connection. It first checks for WebSocket browser support and then verifies if the connection's ready state is 'OPEN' before attempting to send the message. If the socket is not open, an alert is displayed. ```JavaScript function send(message) { if (!window.WebSocket) { return; } if (socket.readyState == WebSocket.OPEN) { socket.send(message); } else { alert("The socket is not open."); } } ``` -------------------------------- ### JavaScript EventBus Handler for Real-time Metrics Dashboard Source: https://github.com/vert-x3/vertx-examples/blob/5.x/kafka-examples/src/main/resources/webroot/index.html This JavaScript code initializes a Vert.x EventBus connection to receive real-time dashboard metrics. It registers a handler for the "dashboard" address, processes incoming JSON data containing various metrics, updates corresponding chart series with new data points, and removes series for metrics that are no longer present. It relies on a `Charts` utility and jQuery for DOM manipulation. ```JavaScript var charts = new Charts(); var eb = new vertx.EventBus("http://" + location.host + "/eventbus"); eb.onopen = function() { eb.registerHandler("dashboard", function(dashboard) { var x = (new Date()).getTime(); // current time console.log(dashboard); for (var id in dashboard) { if (dashboard.hasOwnProperty(id)) { var metrics = dashboard\[id\]; for (var metric in metrics) { if (metrics.hasOwnProperty(metric)) { var chart = charts.getChart(metric); var y = metrics\[metric\]; $("#" + metric + "-val").html(y); var serie = chart.getSerie(id, function() { var data = \[\], time = (new Date()).getTime(),i ; for (i = -19; i <= 0; i += 1) { data.push({ x: time + i \* 1000, y: y }); } return data; }); serie.addPoint(\[x, y\], false, true); } } } } // Remove metrics charts.removeSeries(function(id) { return dashboard\[id\] === undefined; }); // charts.redraw(); }); }; ```