Skip to content

Log Adapter

Overview

Writing custom adapters for Neuron is very common. This sample adapter demonstrates how to write an adapter that subscribes to messages from the ESB and writes the contents of those messages to the Neuron log files and Windows Event Viewer. For more information about writing custom adapters, please see the Adapter Framework sample and documentation.

Running the Sample

Open the Sample

To open this sample, see the topic Using the Neuron Samples and select the Log Adapter sample.

Note: This sample does not open a Neuron ESB Configuration. It only opens a Visual Studio project.

Configure the Sample

When launching this sample from the Samples Explorer, a Visual Studio project is opened. The references in this project need to be verified and the project needs to be built.

  1. In Visual Studio, expand the References list in the Solution Explorer.
  2. There needs to be six references to Neuron ESB Assemblies in this list:
    • ESBService
    • Neuron
    • Neuron.Esb
    • Neuron.Pipelines
    • Neuron.Scripting
    • NeuronExplorer
  3. If the references show an error, remove them and re-add them from the Neuron program files installation directory (C:\Program Files\Neudesic\Neuron ESB v3\DEFAULT).
  4. Build the solution.
  5. Copy the adapter assembly Neuron.Esb.Adapters.LogAdapter.dll from the build output folder (C:\Program Files\Neudesic\Neuron ESB v3\Samples\CustomAdapters\LogAdapter\bin\Debug) to the Adapters folder in the Neuron program files installation directory (C:\Program Files\Neudesic\Neuron ESB v3\DEFAULT\Adapters).

Create a new Neuron Configuration

  1. If Neuron ESB Explorer is already opened, close it and re-open it, and create a new Neuron Configuration.
  2. Navigate to Messaging->Publish and Subscribe->Topics and create a new topic called LogTopic.
  3. Navigate to Messaging->Publish and Subscribe->Publishers and create a new publisher called LogPublisher, and set the subscription to the topic LogTopic (Send).
  4. Navigate to Messaging->Publish and Subscribe->Subscribers and create a new subscriber called LogSubscriber, and set the subscription to the topic LogTopic (Receive).
  5. Navigate to Connections->Connection Methods->Adapter Registration.
  6. Click the New button to register a new adapter:
    Adapter Registration

  7. Set the Name to LogAdapter and select Log Adapter from the Adapter dropdown list:
    Log Adapter

  8. Click the Apply button.
  9. Navigate to Connections->Endpoints->Adapter Endpoints and click the New button.
  10. Set the Name to LogAdapterEndpoint, select LogAdapter from the Adapter dropdown list, select the Mode Subscribe and the Party Id LogSubscriber:
    LogAdapterEndpoint

  11. Select the Proper
    ties tab. This sample only has one property that it uses – Error Level. Set this to reflect which error level you want the messages reported in the log files and Windows Event Viewer. However, the other properties listed are provided as examples of properties of custom adapters (changes these values will be ignored by this sample adapter):
    Error Level

  12. Click the Apply button.
  13. Save the Neuron Configuration by clicking File->Save, then create a new Folder and navigate into that folder:
    File Save

  14. Click the Select button and the configuration will be saved.
  15. Configure the Neuron ESB Service to run the new configuration by clicking the Configure Server button:
    Configure Server button

  16. Set the ESB Configuration Folder to the folder containing the configuration you just saved:
    Set the ESB Configuration Folder

  17. Click Save, then restart the Neuron ESB Service:
    Restart the Neuron ESB Service

Run the Sample

  1. In Neuron ESB Explorer, open a test client from Tools->Test Client->1 Test Client.
  2. Select LogPublisher from the Party Id dropdown list and click the Connect button:
    LogPublisher

  3. Click the Send tab and enter any message. Click the Send button:
    Send tab

  4. Open the Windows Event Viewer and navigate to Applications and Services Logs->Neuron ESB v3. You will see an entry from the adapter in the Neuron event logs:
     Applications and Services Logs

  5. Using Windows Explorer, navigate to the Neuron log files (C:\Program Files\Neudesic\Neuron ESB v3\logs\DEFAULT) and select the most recently created folder.
  6. Open the log file for the LogAdapterEndpoint (i.e. Enterprise_Adapter Endpoint_LogAdapterEndpoint-2013-01-21.log).
  7. You will see something similar to this. Note the last line which is the Warning log message from the adapter:
ESB Trace Log - Machine: JKLUG03 - Trace level: Error+Warning+Info+Verbose
 
2013-01-21 06:01:50.226-08:00 3 info    Starting
2013-01-21 06:01:50.226-08:00 3 info    Service Id = 6dc1ed90-4e90-41d2-8a1e-d3e97986eda8
2013-01-21 06:01:50.226-08:00 3 info    Created proxy to control service
2013-01-21 06:01:50.226-08:00 3 info    Retrieved configuration from control service
2013-01-21 06:01:50.232-08:00 3 info    Starting heartbeat thread
2013-01-21 06:01:50.237-08:00 3 info    Adapter policy: Default
2013-01-21 06:01:50.238-08:00 3 info    Heartbeat thread is waiting for initialization to complete
2013-01-21 06:01:50.238-08:00 3 info    Heartbeat thread is active
2013-01-21 06:01:50.243-08:00 3 info    Setting up adapter endpoint LogAdapterEndpoint
2013-01-21 06:01:50.245-08:00 4 verbose Running under service identity
2013-01-21 06:01:50.245-08:00 3 info    Loading adapter LogAdapter
2013-01-21 06:01:50.308-08:00 3 info    Configuring adapter, mode=Subscribe
2013-01-21 06:01:50.323-08:00 3 info    Property Level = Warning
2013-01-21 06:01:50.323-08:00 3 info    Property AuditOnFailure = False
2013-01-21 06:01:50.324-08:00 3 info    Property PublishTopic =
2013-01-21 06:01:50.324-08:00 3 info    Property PollingInterval = 10
2013-01-21 06:01:50.324-08:00 3 info    Property ErrorMode = Error
2013-01-21 06:01:50.324-08:00 3 info    Property ErrorHandling = StopPollingOnError
2013-01-21 06:01:50.327-08:00 3 info    Connecting party LogSubscriber
2013-01-21 06:01:51.254-08:00 3 info    Connecting to adapter
2013-01-21 06:01:51.266-08:00 3 info    Opened direct connection at net.pipe://localhost/neuron/DEFAULT/direct/adapter/LogAdapterEndpoint
2013-01-21 06:01:51.266-08:00 3 info    Started
2013-01-21 06:04:34.430-08:00 4 verbose Received Message. MessageId 4c6ed16f-13fa-4003-bbad-512919052211 Topic LogTopic
2013-01-21 06:04:34.434-08:00 2 warning <test>This is a test message</test>
 
Was this article helpful?
Dislike 0
Next: Adapter Framework