All Apps and Add-ons

How to pass parameters into a custom JMS Modular Input Message Handler

mcormier_splunk
Splunk Employee
Splunk Employee

I'm working on a project to convert binary JMS message bodies to Strings. I've built the converter and will integrate it using the template you've laid out in Splunk Answers
https://answers.splunk.com/answers/310006/how-to-convert-byte-characters-coming-out-of-mq-th.html

I've run into a problem. The converter uses a properties file to describe the message format. How can I get the file path/name passed into this class so I can load the message format? I see the setParams (Map<String, String> params) method, but don't know
(a) if that's the right call and
(b) how to initialize a parameter that might get passed into this call in the first place.

Anyone have an example of how they've done this, how it might be done, or a pointer to documentation?

0 Karma
1 Solution

Damien_Dallimor
Ultra Champion

Config example :

alt text

Rough code example :

package com.splunk.modinput.jms.custom.handler;

import java.io.File;
import java.util.Map;

import javax.jms.Message;

import com.splunk.modinput.jms.AbstractMessageHandler;
import com.splunk.modinput.jms.JMSModularInput.MessageReceiver;

public class ExampleMessageHandler extends AbstractMessageHandler {

    private final static String MSG_FORMAT_FILE_PARAM = "msg_format_file";

    private File msgFormatFile;

    @Override
    public void handleMessage(Message message, MessageReceiver context) throws Exception {


        String event = decodeMessageBody(message);

        transportMessage(event, String.valueOf(System.currentTimeMillis()), "");

    }

    private String decodeMessageBody(Message message) {
        String result = "";
        try {

           //TODO your logic to pull out the message bytes and decode them

        } catch (Exception e) {}

        return result;

    }

    @Override
    public void setParams(Map<String, String> params) {

        if (params.containsKey(MSG_FORMAT_FILE_PARAM))
            this.msgFormatFile = new File(params.get(MSG_FORMAT_FILE_PARAM));

    }

}

View solution in original post

0 Karma

Damien_Dallimor
Ultra Champion

Config example :

alt text

Rough code example :

package com.splunk.modinput.jms.custom.handler;

import java.io.File;
import java.util.Map;

import javax.jms.Message;

import com.splunk.modinput.jms.AbstractMessageHandler;
import com.splunk.modinput.jms.JMSModularInput.MessageReceiver;

public class ExampleMessageHandler extends AbstractMessageHandler {

    private final static String MSG_FORMAT_FILE_PARAM = "msg_format_file";

    private File msgFormatFile;

    @Override
    public void handleMessage(Message message, MessageReceiver context) throws Exception {


        String event = decodeMessageBody(message);

        transportMessage(event, String.valueOf(System.currentTimeMillis()), "");

    }

    private String decodeMessageBody(Message message) {
        String result = "";
        try {

           //TODO your logic to pull out the message bytes and decode them

        } catch (Exception e) {}

        return result;

    }

    @Override
    public void setParams(Map<String, String> params) {

        if (params.containsKey(MSG_FORMAT_FILE_PARAM))
            this.msgFormatFile = new File(params.get(MSG_FORMAT_FILE_PARAM));

    }

}
0 Karma

mcormier_splunk
Splunk Employee
Splunk Employee

Thanks for this! I was hoping it would be straightforward to use setParams(), just didn't know the "config" side of the equation. I will test it out and report back.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...