Skip to content

Instantly share code, notes, and snippets.

@nczeczulin
Created August 1, 2013 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nczeczulin/6129089 to your computer and use it in GitHub Desktop.
Save nczeczulin/6129089 to your computer and use it in GitHub Desktop.
Splunk Modular Input for MSMQ - Example Message Handler Template
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.Messaging;
using MessageHandlerContracts = Splunk.ModularInput.Msmq.MessageHandlerContracts;
namespace Example
{
[Export("ExampleHandler.Template", typeof(MessageHandlerContracts.IMessageHandler))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class ExampleHandlerTemplate : MessageHandlerContracts.IMessageHandler
{
public System.Messaging.IMessageFormatter MessageBodyFormatter { get; private set; }
public System.Messaging.MessagePropertyFilter MessageReadPropertyFilter { get; private set; }
[ImportingConstructor]
public ExampleHandlerTemplate()
{
MessageReadPropertyFilter = new MessagePropertyFilter();
// Note, both MessageReadPropertyFilter and MessageBodyFormatter _must_ be configured either
// here, or during SetConfiguration
}
/// <summary>
/// This method is called after instantiation.
/// Also called during external validation if Manager>>Data Inputs>>MSMQ Messaging is used to configure
/// the input stanza.
/// </summary>
/// <param name="handlerArgs"></param>
public void SetConfiguration(string handlerArgs)
{
// do stuff.
// throw an exception if required.
}
/// <summary>
/// This method is called for every msmq message that is processed.
/// The returned string will be the "event data" forwarded to splunk.
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
public string GetSplunkEventData(System.Messaging.Message msg)
{
// add code
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment