This project contains a sample implementation of a Service Broker based on the Spring Cloud Open Service Broker
It provides the following solutions:
- Dispatching of multiple services (service definitions) by the very same broker
Build the service broker application with
./gradlew clean build
Run the service broker application with
./gradlew clean bootRun
Run the tests with
./gradlew clean test -i
Let's say you want to implement a handler for a new Mega
service:
- Create a new class
MegaServiceInstanceRequestHandler
in thech.lihsmi.demobroker.service.handler
package. - This class needs to implement the
ServiceInstanceRequestHandler
interface and must be annotated with the@ServiceInstanceRequestHandlerBean
annotation. - Make sure that the
getServiceDefinitionId()
method returns the service definition ID which is processed by your new handler (mega
) as defined in the service plan of the broker. - Implement handler logic in
handleRequest()
Sample code:
package ch.lihsmi.demobroker.service.handler;
import org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest;
import org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse;
import org.springframework.stereotype.Component;
@Component
@ServiceInstanceRequestHandlerBean
public class MegaServiceInstanceRequestHandler implements ServiceInstanceRequestHandler {
private final String serviceDefinitionId = "mega";
@Override
public CreateServiceInstanceResponse handleRequest(final CreateServiceInstanceRequest request) {
return CreateServiceInstanceResponse.builder()
.operation(serviceDefinitionId)
.build();
}
// implement further methods of the ServiceInstanceRequestHandler interface as required
@Override
public String getServiceDefinitionId() {
return serviceDefinitionId;
}
}