Apigee MessageLogging policy has limitation to use configurable parameters such as Syslog server host, port, etc. details. If we are not going to configure these parameters we may get into trouble while moving the proxy from one environment to another environment. To achieve the portability the approach is to have MessageLogging policy for each environment. Based on the environment in which the proxy is running the policy will be applied. Below is the sample proxy with message logging policy for each environment. The proxy definition is given below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<ProxyEndpoint name="default"> | |
<Description/> | |
<FaultRules/> | |
<PreFlow name="PreFlow"> | |
<Request/> | |
<Response/> | |
</PreFlow> | |
<PostFlow name="PostFlow"> | |
<Request/> | |
<Response> | |
<Step> | |
<Name>TestEnv-Message-Logging</Name> | |
<Condition>environment.name = "test"</Condition> | |
</Step> | |
<Step> | |
<Name>ProdEnv-Message-Logging</Name> | |
<Condition>environment.name = "prod"</Condition> | |
</Step> | |
</Response> | |
</PostFlow> | |
<Flows/> | |
<HTTPProxyConnection> | |
<BasePath>/messgageloggingdemo</BasePath> | |
<Properties/> | |
<VirtualHost>default</VirtualHost> | |
<VirtualHost>secure</VirtualHost> | |
</HTTPProxyConnection> | |
<RouteRule name="noroute"/> | |
</ProxyEndpoint> |
The test and prod environment MessageLogging policy configuration is given below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<MessageLogging async="false" continueOnError="false" enabled="true" name="TestEnv-Message-Logging"> | |
<DisplayName>TestEnv Message Logging</DisplayName> | |
<Syslog> | |
<Message>{environment.name}</Message> | |
<Host>10.0.0.1</Host> | |
<Port>556</Port> | |
</Syslog> | |
</MessageLogging> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<MessageLogging async="false" continueOnError="false" enabled="true" name="ProdEnv-Message-Logging"> | |
<DisplayName>ProdEnv Message Logging</DisplayName> | |
<Syslog> | |
<Message>{environment.name}</Message> | |
<Host>10.0.0.2</Host> | |
<Port>448</Port> | |
</Syslog> | |
</MessageLogging> |
The proxy demonstrated is available on GitHub to download and play with it.
Leave a Reply