Skip to content

Vertx Service Proxy

DodaTech 1 min read

In this tutorial, you'll learn about Fix Vert.x Service Proxy Not Working. We cover key concepts, practical examples, and best practices.

The Problem

Service proxy does not route calls to the actual service implementation.

Quick Fix

Define service interface

Wrong:

// No service interface
public class ProductService {
    public void save(Product p) { }
}

Output:

No proxy generated

Right:

@ProxyGen
@VertxGen
public interface ProductService {
    void save(Product p, Handler<AsyncResult<Void>> handler);
}

Output:

Service interface defined

Create service handler

Wrong:

// No service handler
ServiceBinder binder = new ServiceBinder(vertx);

Output:

No binding

Right:

new ServiceBinder(vertx)
    .setAddress("product.service")
    .register(ProductService.class, new ProductServiceImpl());

Output:

Service registered

Create proxy client

Wrong:

// No proxy
ProductService service = ProxyHelper.createProxy(ProductService.class, vertx, "product.service");

Output:

Proxy created

Right:

ProxyHelper.createProxy(ProductService.class, vertx, "product.service")
    .save(product, result -> {
        if (result.succeeded()) log.info("Saved");
    });

Output:

Proxy invoked

Prevention

  • Define service interface with @ProxyGen
  • Register service with ServiceBinder
  • Create proxy client with ProxyHelper.createProxy()

Common Mistakes with service proxy

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world VERTX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does the proxy return null?

The service must be registered before the proxy is created. Ensure registration happens at startup.

This quick fix is part of the DodaTech Spring & JVM ecosystem series. Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro