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@MyManasgedServer_osb1@My.TOPIC.NAME
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
.
The JMS API does not support any way to delete a message without actually consuming it.