Description
Load balancing can be used to improve both security and performance. This KB article shows a common load-balancing configuration with one content authoring (CA) server and two content delivery (CD) servers and is based on events documentation.
In this example, content authors publish on the CA server which, in turn, broadcasts events to a listening service on the two Content Delivery (CD) servers. Next, a "publish is made" event is generated on CA, which expires the cache on CD1 and CD2. The cache on CD1 and CD2 is then regenerated by pulling the updated content from the database (shared by all three servers). At this point, the published content should be the same on all three servers.
Below is how you can configure events for such a configuration.
Steps
Note that the below example may not apply to your circumstances. Please see the additional resources at the bottom if you have further questions about configuring WCF events with Episerver. Also note that this was configured in Episerver CMS 10 and may not work in other versions.
- Configure the web.config of the broadcasting server, in this case CA. If content updates are not made on the CD servers, you do not need to configure a service section on the CA servers.
- Locate the system.serviceModel section and then the serviceHostingEnvironment tag within that. See step 1.5 for what this looks like.
- There should be a client tag inside the serviceHostingEnvironment section. If not, add one like the one below. The endpoints in the client tag should have the IP addresses of the CD servers. You need to open a port on the CD servers and include that port in the endpoints as well. If CD1 had an IP address of 192.168.1.2 with port 5000 open, and CD2 had an IP address of 192.168.1.3 also with port 5000 open, the client section on CA would look like this.
<client> <endpoint name="192.168.1.2:5000" address="net.tcp://192.168.1.2:5000/RemoteEventService" binding="netTcpBinding" bindingConfiguration="RemoteEventsBinding" contract="EPiServer.Events.ServiceModel.IEventReplication" /> <endpoint name="192.168.1.3:5000" address="net.tcp://192.168.1.3:5000/RemoteEventService" binding="netTcpBinding" bindingConfiguration="RemoteEventsBinding" contract="EPiServer.Events.ServiceModel.IEventReplication" /> </client>
- After the client section, add a behaviors section.
<behaviors> <serviceBehaviors> <behavior name="DebugServiceBehaviour"> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors>
- Next is a bindings section. You may have an indexing service binding here as well, so adjust as needed.
<bindings> <netTcpBinding> <binding name="RemoteEventsBinding" portSharingEnabled="true"> <security mode="None" /> </binding> </netTcpBinding> </bindings>
- When all said and done, your CA web.config's system.ServiceModel section would look like this.
<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <client> <endpoint name="192.168.1.2" address="net.tcp://192.168.1.2:5000/RemoteEventService" binding="netTcpBinding" bindingConfiguration="RemoteEventsBinding" contract="EPiServer.Events.ServiceModel.IEventReplication" /> <endpoint name="192.168.1.3" address="net.tcp://192.168.1.3:5000/RemoteEventService" binding="netTcpBinding" bindingConfiguration="RemoteEventsBinding" contract="EPiServer.Events.ServiceModel.IEventReplication" /> </client> <behaviors> <serviceBehaviors> <behavior name="DebugServiceBehaviour"> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <bindings> <netTcpBinding> <binding name="RemoteEventsBinding" portSharingEnabled="true"> <security mode="None" /> </binding> </netTcpBinding> </bindings> </system.serviceModel>
- Now that the CA server is configured, you need to configure the CD servers to be listening services to the CA server. There is no client section needed in the CD servers. On the CD servers, WCF only needs to listen on its service address.
- Again locate the <system.serviceModel> section and then the serviceHostingEnvironment tag within that.
- There should be a service tag inside the serviceHostingEnvironment section. If not add one like the one below. The CD server's IP address and port you wish to listen on for cache expiring events are listed in this section. If CD1 is 192.168.1.2, its service would look like this.
<services> <service name="EPiServer.Events.Remote.EventReplication"> <endpoint name="RemoteEventServiceEndPoint" contract="EPiServer.Events.ServiceModel.IEventReplication" bindingConfiguration="RemoteEventsBinding" address="net.tcp://192.168.1.2:5000/RemoteEventService" binding="netTcpBinding" /> </service> </services>
- If CD2 is 192.168.1.3, its service would look like this.
<services> <service name="EPiServer.Events.Remote.EventReplication"> <endpoint name="RemoteEventServiceEndPoint" contract="EPiServer.Events.ServiceModel.IEventReplication" bindingConfiguration="RemoteEventsBinding" address="net.tcp://192.168.1.3:5000/RemoteEventService" binding="netTcpBinding" /> </service> </services>
- Add the behaviors section.
<behaviors> <serviceBehaviors> <behavior name="DebugServiceBehaviour"> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors>
- Add the bindings section.
<bindings> <netTcpBinding> <binding name="RemoteEventsBinding" portSharingEnabled="true"> <security mode="None" /> </binding> </netTcpBinding> </bindings>
- Once finished, your CD1 config should look like this. CD2 would be identical except the endpoint would have a different IP address.
<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <services> <service name="EPiServer.Events.Remote.EventReplication"> <endpoint name="RemoteEventServiceEndPoint" contract="EPiServer.Events.ServiceModel.IEventReplication" bindingConfiguration="RemoteEventsBinding" address="net.tcp://192.168.1.2:5000/RemoteEventService" binding="netTcpBinding" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="DebugServiceBehaviour"> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <bindings> <netTcpBinding> <binding name="RemoteEventsBinding" portSharingEnabled="true"> <security mode="None" /> </binding> </netTcpBinding> </bindings> </system.serviceModel>
Test by modifying and publishing a page on CA and verifying CD1 and CD2 received the change.
This is just one load-balancing example so modify it to suit your needs. See the below resources for more information on configuring events over WCF.
Also please note:
For Commerce Connect cart/order processing you will need to also setup up event listeners. The servers that are setup as Services also need to be setup as clients of each other so that if a cart changes on one server, this event gets reflected on the other server and that cart updates as well; otherwise, the carts could be different at any point in time.
Once a cart changes on one server, an event is fired and the other servers pick up the change.
Please sign in to leave a comment.