-1

I have been working on some code to delete messages from a JMS topic without having them be consumed from our DB (due to some issues with our DB). I figured out that there is no dedicated method for deleting messages directly from the topic, but I've been trying to create a JMS connection and create the topic and consumer and use that to delete the messages.

The issue I'm having is after the JMS session is created in my code it should create the topic using an existing topic, create a consumer, then loop through the consumer and remove the messages. The problem arises during the topic creation where I'm not sure if I'm formatting the topic name wrong or what but I need to either get an example of what the correct syntax of the topic should be or if maybe there is a different issue. Also, separately I was able to list out the names of the topics in my fusion environment but the format that I got didn't work either, it looked like this:

myJMSModule!MyJMSServer@[email protected]

Here is my code:

                    context = InitialContext(jndi_props)
                    connection_factory = context.lookup("my/connectionFactory")
                    connection = connection_factory.createConnection()
                    session = connection.createSession(False, javax.jms.Session.AUTO_ACKNOWLEDGE)
                    topic =    session.createTopic("Where im having issues")
                    consumer = session.createConsumer(topic, selector)
                    connection.start()



                    try:
                       while True:
                           message = consumer.receiveNoWait()
                           if message is None:
                               break

                           if isinstance(message, JMSMessageInfo):
                              print("Removing message: %s " % message.getJMSMessageID())
                              session.deleteMessage(message) # Acknowledge the message to remove it



                    finally:
                       consumer.close()
                       session.close()
                       connection.close()

this is one of the errors I usually get:

weblogic.jms.common.JMSException: weblogic.jms.common.JMSException: [JMSExceptions:045103]While trying to find a topic or a queue, the specific JMS server requested could not be found. The linked exception may contain more information about the reason for failure.

I need some help on this or if you know a better way to delete the messages from a topic without consuming them that would also be very helpful.

At the session.createTopic is where my issues are arising. I've tried formats like My.TOPIC.NAME, /My.TOPIC.NAME, myJMSServer/My.TOPIC.NAME, myJMSModule/My.TOPIC.NAME.

5
  • It doesn't make sense to "delete messages from a JMS topic" in the first place because a JMS itself topic doesn't store messages. Messages are stored in subscriptions and typically only the original subscriber will be able to access those messages. If you just create a consumer on a topic then that consumer's subscription will receive all the messages just like all the other subscriptions on the topic. Deleting these messages will have no impact on the other subs. Also, there is no deleteMessage method in JMS. The way to "delete" a message is to receive & acknowledge it with a consumer. Commented Oct 9, 2024 at 13:27
  • Well we were trying to delete them because our topic has millions of messages that need to be consumed and like up when we activate our proxy service and and we can’t have them consumed because our subscriber causes issues in production when active. We were trying to figure out a way to remove them without consumption. Is that possible? Commented Oct 9, 2024 at 14:53
  • Are you using durable or non-durable subscriptions from your JMS application(s)? Can you not delete the messages administratively? What's the difference between receiving & acknowledging the messages vs. deleting them? The result is the same in both instances - the message is gone. Commented Oct 9, 2024 at 15:52
  • We can but we were trying to automate the process of deletion because there is so many messages Commented Oct 9, 2024 at 16:18
  • Does your broker not offer a way to delete message in bulk? Commented Oct 9, 2024 at 16:20

1 Answer 1

0

The JMS API does not support any way to delete a message without actually consuming it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.