-
Notifications
You must be signed in to change notification settings - Fork 0
Service Discovery
ServiceStack is fortunate to have a vibrant community which quickly saw the capabilities on offer in Service Gateway whom have jumped in with a number of high-quality, well-documented and supported value-added OSS solutions:
The ConsulFeature plugin by Scott Mackay leverages the hardened distributed Discovery Services and highly available features in consul.io to provide automatic registration and de-registration of ServiceStack Services on AppHost StartUp and Dispose that's available from:
PM> Install-Package ServiceStack.Discovery.Consul
Without any additional effort beyond registering the ConsulFeature
plugin and starting a new ServiceStack
Instance it provides an auto-updating, self-maintaining and periodically checked registry of available Services:
public override void Configure(Container container)
{
SetConfig(new HostConfig {
WebHostUrl = "http://api.acme.com:1234", // Externally resolvable BaseUrl
});
Plugins.Add(new ConsulFeature()); // Register the plugin, that's it!
}
Once registered, the Service Gateway works as you'd expect where internal requests are executed in process and external requests queries the Consul registry to discover the appropriate and available Service to call:
public class MyService : Service
{
public void Any(RequestDTO dto)
{
// Gateway will automatically route external requests to correct service
var internalCall = Gateway.Send(new InternalDTO { ... });
var externalCall = Gateway.Send(new ExternalDTO { ... });
}
}
The RedisServiceDiscoveryFeature by Richard Safier has similar goals to provide transparent service discovery but only requires access to Redis-backed datastore, but is otherwise just as easy to install:
PM> Install-Package ServiceStack.Discovery.Redis
and Configure:
public override void Configure(Container container)
{
container.Register<IRedisClientsManager>(c => new RedisManagerPool(...));
SetConfig(new HostConfig {
WebHostUrl = "http://api.acme.com:1234"
});
Plugins.Add(new RedisServiceDiscoveryFeature());
}
Once registered, calling the same Gateway API's function the same way with internal requests executed internally and external requests sent to the appropriate available node:
public class MyService : Service
{
public void Any(RequestDTO dto)
{
var internalCall = Gateway.Send(new InternalDTO { ... });
var externalCall = Gateway.Send(new ExternalDTO { ... });
try
{
var unknown = Gateway.Send(new ExternalDTOWithNoActiveNodesOnline());
}
catch(RedisServiceDiscoveryGatewayException e)
{
// If a DTO type is not local or resolvable by Redis discovery process
// a RedisServiceDiscoveryGatewayException will be thrown
}
}
}
Since all Redis Discovery data is stored in a redis instance the state of all available nodes can be viewed with any Redis GUI:
In addition to this Redis Discovery Service Richard is also developing a series of ServiceStack plugins that enhances the functionality of ServiceStack.Discovery.Redis and provides cluster awareness to additional aspects of a ServiceStack AppHost's internal state.
- Why ServiceStack?
- Important role of DTOs
- What is a message based web service?
- Advantages of message based web services
- Why remote services should use separate DTOs
-
Getting Started
-
Designing APIs
-
Reference
-
Clients
-
Formats
-
View Engines 4. Razor & Markdown Razor
-
Hosts
-
Security
-
Advanced
- Configuration options
- Access HTTP specific features in services
- Logging
- Serialization/deserialization
- Request/response filters
- Filter attributes
- Concurrency Model
- Built-in profiling
- Form Hijacking Prevention
- Auto-Mapping
- HTTP Utils
- Dump Utils
- Virtual File System
- Config API
- Physical Project Structure
- Modularizing Services
- MVC Integration
- ServiceStack Integration
- Embedded Native Desktop Apps
- Auto Batched Requests
- Versioning
- Multitenancy
-
Caching
-
HTTP Caching 1. CacheResponse Attribute 2. Cache Aware Clients
-
Auto Query
-
AutoQuery Data 1. AutoQuery Memory 2. AutoQuery Service 3. AutoQuery DynamoDB
-
Server Events
-
Service Gateway
-
Encrypted Messaging
-
Plugins
-
Tests
-
ServiceStackVS
-
Other Languages
-
Amazon Web Services
-
Deployment
-
Install 3rd Party Products
-
Use Cases
-
Performance
-
Other Products
-
Future