Class ForwardingWebConsumer

java.lang.Object
io.fluxzero.sdk.web.ForwardingWebConsumer
All Implemented Interfaces:
AutoCloseable

public class ForwardingWebConsumer extends Object implements AutoCloseable
A specialized, opt-in web request consumer that forwards incoming MessageType.WEBREQUEST messages to a locally running HTTP server.

This class is internally initialized when FluxzeroBuilder.forwardWebRequestsToLocalServer(int) is configured. Rather than routing messages through Fluxzero's internal handler infrastructure, it converts web requests into raw HTTP requests and asynchronously sends them to http://localhost:port.

Purpose

This mechanism exists primarily for interoperability: it allows applications to integrate with their own HTTP servers (e.g., frameworks like Spring Boot, Quarkus, or Vert.x) rather than adopting the Fluxzero message-based web handler framework.

⚠️ Caution: Limited Use Case

While supported, use of this component is generally discouraged. It bypasses the core pull-based message consumption model of Fluxzero by pushing messages asynchronously to a local server. This introduces a risk of losing delivery guarantees, tracing consistency, and handler lifecycle control.

Consider using @HandleWeb-based handlers and declarative routing instead.

How It Works

  • Consumes WEBREQUEST messages via a Tracker
  • For each message, creates a corresponding HttpRequest and sends it to localhost
  • Captures the HttpResponse and converts it back into a SerializedMessage
  • Publishes the result using the WEBRESPONSE GatewayClient

Features

  • Header forwarding with filtering of restricted headers
  • Support for request correlation and metadata propagation
  • Graceful handling of 404s (configurable via LocalServerConfig#isIgnore404())
  • Fallback error response creation if the target server fails
See Also:
  • Constructor Details

  • Method Details

    • start

      public void start(Fluxzero fluxzero)
    • responseGateway

      protected GatewayClient responseGateway(Fluxzero fluxzero)
    • getCorrelationData

      protected Map<String,String> getCorrelationData(io.fluxzero.common.api.SerializedMessage m)
    • createRequest

      protected HttpRequest createRequest(io.fluxzero.common.api.SerializedMessage m)
    • isRestricted

      protected boolean isRestricted(String headerName)
    • toMessage

      protected io.fluxzero.common.api.SerializedMessage toMessage(HttpResponse<byte[]> response, Map<String,String> correlationData)
    • toMessage

      protected io.fluxzero.common.api.SerializedMessage toMessage(Throwable error, Map<String,String> correlationData)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable