Remote procedure calls
The dealer routes calls to either an annotated Spring bean method or a procedure registered by a WAMP client. Enable Feature.DEALER (the default).
Java procedures and arguments
@WampProcedure("calc.add") and @WampProcedure(name = "calc.add") are equivalent. Omitting the name uses beanName.methodName. The annotated class must be a Spring bean.
import java.security.Principal;
import org.springframework.stereotype.Service;
import ch.rasc.wamp2spring.annotation.WampProcedure;
import ch.rasc.wamp2spring.annotation.WampSessionId;
import ch.rasc.wamp2spring.message.CallMessage;
@Service
public class CalculatorService {
@WampProcedure("calc.add")
public int add(int left, int right, @WampSessionId Long sessionId,
Principal principal, CallMessage message) {
return left + right;
}
}
The client sends only left and right. The remaining parameters are resolved from message metadata and do not consume positional arguments. This example requires an authenticated principal: an anonymous session cannot bind the Principal parameter. For optional identity, accept CallMessage and inspect its nullable getPrincipal() instead. @WampSessionId refers to the WAMP session ID, not the transport's string ID.
Ordinary parameters bind from positional arguments, then keyword arguments by Java parameter name. Compile application handlers with -parameters to retain those names. Spring conversion and Jackson value conversion support typed objects and collections. An unresolved or null parameter is a binding error, including when a metadata resolver returns null; inspect the original message for optional values. Add custom resolvers through WampConfigurer.addArgumentResolvers.
await session.call("calc.add", [3, 10]);
await session.call("calc.add", [], {left: 3, right: 10});
Return values
| Java return value | WAMP result |
|---|---|
void or null |
No positional or keyword payload |
List<?> |
The list becomes the positional results |
Map<String, ?> |
The map becomes keyword results |
| Other non-null value | One positional result containing that value |
WampResult |
Explicit positional and/or keyword results |
Use ch.rasc.wamp2spring.rpc.WampResult to control the shape:
return new WampResult().add(13).add("unit", "items");
To return a list or map as one positional value, wrap it with new WampResult().add(value). This differs from returning a bare list or map.
Methods execute synchronously on the inbound worker. The handler does not await CompletionStage or adapt Mono/Flux, and it emits one result per Java invocation. Dealer cancellation and timeout tracking apply to routed client invocations; they do not interrupt or time out an annotated Java method. Progressive call chunks to a Java method return wamp.error.feature_not_supported.
Errors
Throw WampException to choose the error URI and optional payload:
throw new WampException.Builder()
.argumentsKw(Map.of("field", "quantity"))
.build("app.error.invalid_quantity");
Import ch.rasc.wamp2spring.WampException and java.util.Map, and declare throws WampException. Ordinary method/binding exceptions become wamp.error.invalid_argument. A directly thrown Spring Security AccessDeniedException becomes wamp.error.not_authorized.
Procedures registered by clients
REGISTER.Options.match supports exact (default), prefix, and wildcard. Prefix matching is a string prefix; a wildcard is an empty dot-separated component, such as app..read, not *. Registration routing checks exact matches first, then prefix matches (preferring more URI components), then wildcard specificity. An annotated procedure with the exact called name is checked before the client registry.
REGISTER.Options.invoke supports single (default), roundrobin, random, first, last, and sharded. Shared registrations must use a compatible invocation policy. With sharded, calls carry a string rkey; selection uses its Java string hash modulo the current callee count. Changes in the callee set can change routing.
Client registration of the reserved wamp. namespace is rejected. Exact call and registration URIs must have nonempty dot-separated components and may not contain whitespace or #.
Advanced invocation flow
- Timeout: a positive
CALL.Options.timeoutis in milliseconds and requires callercall_timeoutsupport. The dealer enforces the timer even if the callee lacks timeout support; supporting callees also receive the value. Progressive results restart the pending invocation's timer. - Cancellation:
skipstops waiting for the result without interrupting the callee;killsends an interrupt to a supporting callee and waits for completion;killnowaitinterrupts a supporting callee and returns cancellation immediately. Unsupported callees use dealer-managed completion.killandkillnowaitrequire caller negotiation. - Progressive results: the caller requests
receive_progress; the dealer forwards progress from a supporting callee and keeps the call pending until a finalYIELDorERROR. - Progressive invocations: a supporting caller can send multiple
CALLchunks under the same request ID, ending withprogress: false; the target callee must support the feature. - Disclosure:
disclose_merequests caller details in the invocation. Disabling identification rejects this option withwamp.error.option_disallowed.disclose_me. - Rerouting: a supporting callee's
wamp.error.unavailablecan trigger selection of another eligible callee; this is controlled byDEALER_CALL_REROUTEand peer negotiation.
Administrative Java code can call RpcMessageHandler.revokeRegistration(long registrationId, String reason). It removes the registration's callees and sends extended UNREGISTERED messages to peers that negotiated revocation. This is not a wamp.registration.revoke RPC. See MetaAPIs for inspection procedures and Events for lifecycle events.
Source: RpcMessageHandler, ProcedureRegistry.
Table of Contents
- Introduction
- Quickstart
- Maven
- Modules
- Features
- Configuration
- RPC
- Publish/Subscribe
- Meta APIs
- Security
- Authentication
- Transports
- Spring Session
- Events