Restrict services to run in defined nodes only in a cluster

Image for post
Image for post

In order to restrict the synapse services such as proxies getting deployed and process with the services in all the nodes in a cluster, we can used pinnedServers attribute in the synapse configuration.

Let’s take an example of using mailto transport.

Use case: We have a clustered environment and we need to monitor an inbox mail and process this mails with a proxy service. But we want only one node to listen to these mails without processing them in every node.

You can define the pinnedServer option in the proxy. It defines which server should process with the service. You can give a list of Synapse server names, where this Proxy Service should be deployed using pinnedServers attribute. It takes the server names separated by comma or spaces. If there is no pinned server list, then the Proxy Service will be started in all server instances. If a pinned server name list is given, it will only start in the given named Synapse server instances.

In order to get that done we have follow below simple steps.

It needs to do configurations as in this document to process with mailto transport.

Assume that we have a two node cluster. We want to process mails only in node1.

First it needs to define the server name in the /PRODUCT_HOME/conf/axis2/axis2.xml in both the nodes.

node1= server1


Node1: axis2 config

<parameter name="SynapseConfig.ServerName" locked="false">server1</parameter>

Node 2: axis2 config

<parameter name="SynapseConfig.ServerName" locked="false">server2</parameter>

You can use the pinnedServers attribute in the proxy as below.

<?xml version="1.0" encoding="UTF-8"?><proxy xmlns=""     name="JasperEmailPOP3" 
<property expression="get-property('transport', 'From')" name="senderAddress" scope="default" type="STRING"/>
<log level="custom">
<property expression="$trp:Date" name="Date"/>
<property expression="$trp:Subject" name="Subject"/>
<property expression="$trp:Content-Type" name="Content-Type"/>
<property expression="$trp:From" name="From"/>
<parameter name="mail.pop3.socketFactory.class"></parameter>
<parameter name="transport.PollInterval">5</parameter>
<parameter name=""></parameter>
<parameter name="mail.pop3.user">xxxxxxxx</parameter>
<parameter name="transport.mail.Protocol">pop3</parameter>
<parameter name="mail.pop3.socketFactory.port">995</parameter>
<parameter name="transport.mail.Address">xxxxxxxxxx</parameter>
<parameter name="mail.pop3.password">xxxxxxxxxx</parameter>
<parameter name="mail.pop3.port">995</parameter>
<parameter name="mail.pop3.socketFactory.fallback">false</parameter>
<parameter name="transport.mail.ContentType">text/plain</parameter>

Note that pinnedServers attribute has been defined for server1.

Restart the servers and process with the mails. Only node1 will process the mails as we have defined only that in the pinnedServers attribute.

Written by

Senior Software Engineer — QA at WSO2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store