# Java API: Working with the Topic String

**URL:** <https://community.solace.com/t/java-api-working-with-the-topic-string/400>\
**Category:** Connectors & Integrations\
**Tags:** java, spring-cloud-stream\
**Created:** [September 17, 2020, 3:19pm UTC](https://community.solace.com/t/java-api-working-with-the-topic-string/400 "2020-09-17T15:19:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominik](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dominik](https://community.solace.com/u/Dominik)\
**Post date:** [September 17, 2020, 3:19pm UTC](https://community.solace.com/t/java-api-working-with-the-topic-string/400/1 "2020-09-17T15:19:45Z")

</div>

Hello together,  
we are currently starting with Solace development and want to build different use cases. First we created a topic hierarchy, where for example a source systems stores different data parts in the topic string like:  
`${sourceSystem}/${stage}/${businessObject}/${objectId}`  
Now we want to extract different parts of this hierarchy on a message basis to build some business logic on top of it.  
I saw an unsolved Github issue for the Spring Cloud Framework to store this destination string in the Message header.  
In the core Java API you are getting the destination as a string and have to cut it manually in pieces.

```auto
    public void onReceive(BytesXMLMessage message) {
        String[] levels = message.getDestination().getName().split("/");

```

What is your suggested way to deal with this problem ?  
Furthermore, is this not a common use case for the topic hierarchy ?  
For example based on the `${sourceSystem}` i want to route my messages to a different topic endpoint .  
Thank you

---

<div class="post-metadata">

**Author:** ![TomF](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/tomf/32/1749_2.png) [@TomF](https://community.solace.com/u/TomF)\
**Post date:** [September 17, 2020, 3:40pm UTC](https://community.solace.com/t/java-api-working-with-the-topic-string/400/2 "2020-09-17T15:40:37Z")

</div>

Hi @Dominik,  
I can’t help but feel you’re approaching this problem the wrong way. _Don’t_ do topic filtering in your business logic. Let the broker do that for you - that’s what it’s there for.  
So, instead of having your application receive all messages and direct them to different topic endpoints, have the topic endpoints subscribe to different topics:  
System1 endpoint subscription: system1/\>  
System2 endpoint subscription: system2/\>  
That way you have your sourceSystem directed to different applications _without the application even being aware of this, or seeing messages for other systems_. Even better, don’t use topic endpoints, use queues with topic to queue mapping. Much better!

---

<div class="post-metadata">

**Author:** ![marc](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/marc/32/2191_2.png) [@marc](https://community.solace.com/u/marc)\
**Post date:** [September 22, 2020, 1:46pm UTC](https://community.solace.com/t/java-api-working-with-the-topic-string/400/3 "2020-09-22T13:46:33Z")

</div>

Great info @TomF.

@Dominik, as a heads up @Aaron created [this youtube video](https://youtu.be/PP1nNlgERQI) if you want a quick crash course on solace topics 🙂
