Accessing stream messages in plugin

Hi,

I’m wondering, what is the best way to access messages in a stream within the context of a plugin? I’d appreciate any thoughs on accessing/querying the stored messages, even just the relevant class names are appreciated.

Thanks

Hey @jrunu,

you should take a look at the org.graylog2.indexer.searches.Searches class it exposes this method:

public SearchResult search(String query, String filter, TimeRange range, int limit, int offset, Sorting sorting)

which you can use. Limiting it to a stream means adding a filter to the query, looking like this: streams:<stream id>, where <stream id> is the hexadecimal id of the stream you want to search in.

Does this help?

Hi dennis, it what I just tried out and it worked. Though I used it with a SearchConfig like the API Endpoint does. The signature you suggest is basically the short-hand for that. Its good to know that this is the way to go. Originally I was looking for hopping from org.graylog2.plugin.streams.Stream to a “stream of messages”. Of course I’m now using Stream::getID() as filter.

Thanks!

Originally I was looking for hopping from org.graylog2.plugin.streams.Stream to a “stream of messages”.

We are keeping value objects like Stream as dumb and independent as possible, instead of using something like an “Active Record” pattern. I am not saying one or another is better, this is just our internal convention.

I’m still in the process of familiarizing myself with the codebase. I wasn’t suggesting anything as preferable, just making sure that I use and understand the things as intended. Being aware of the conventions helps there as well.

Have a nice weekend.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.