Author |
Message
|
arunsenthild |
Posted: Tue Feb 12, 2008 10:10 am Post subject: Removing a single message using JAVA code |
|
|
Novice
Joined: 24 Dec 2007 Posts: 11
|
Hi i'm having a message in the queue
I want to remove the message from the queue with the JAVA code.
I used receiver.receivernowait and session.commit to delete the message, but i'm not able to delete the message.
Can u help me regarding this.
Note: The message i'm using is a bytes message.
Many thanks in advance. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Feb 12, 2008 3:14 pm Post subject: Re: Removing a single message using JAVA code |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
arunsenthild wrote: |
Hi i'm having a message in the queue
I want to remove the message from the queue with the JAVA code.
I used receiver.receivernowait and session.commit to delete the message, but i'm not able to delete the message.
Can u help me regarding this.
Note: The message i'm using is a bytes message.
Many thanks in advance. |
You need to use matching options for messageId in java base and a selector in JMS...
session.createReceiver(Destination, selector)
selector is something like
"JMSMessageId='ID:xxxxxxxxxxxx'";
where xxxx is the hex representation of the byte array or
msgid = msg.getJMSMessageId()
selector="JMSMessageId='"+msgid+"'";
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Feb 12, 2008 3:20 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I don't see why using a selector would affect syncpoint or browse options. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Feb 12, 2008 3:31 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
jefflowrey wrote: |
I don't see why using a selector would affect syncpoint or browse options. |
He is talking about receive... so obviously he is using JMS.
So browsing a queue there is no way in JMS to get the message under the cursor... You do a receive with the appropriate selector. Then commit the session... And it might be best to close the browser before doing a receive...
Remember as well that the browser shows a snapshot of the queue's content. If that content is not static (meaning that you are not the only consumer) you might have surprises...
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Feb 12, 2008 4:44 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
fjb_saper wrote: |
jefflowrey wrote: |
I don't see why using a selector would affect syncpoint or browse options. |
He is talking about receive... so obviously he is using JMS. |
Yes, but there's no particular reason arunsenthild would be doing a browse, right?
A receiver should just do a plain old get, either in syncpoint or not, unless one goes to some effort to set it up to browse? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Feb 12, 2008 8:33 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
jefflowrey wrote: |
Yes, but there's no particular reason arunsenthild would be doing a browse, right?
A receiver should just do a plain old get, either in syncpoint or not, unless one goes to some effort to set it up to browse? |
You're right, he enquired about removing a single message from a queue. I took it to mean a single specific message... you'd get the info on it using a QueueBrowser...
If he is indiscriminate about the message but has not been able to receive it, and the message is in a receivable state, I'd bet he forgot to start the connection... (JMS101)  _________________ MQ & Broker admin |
|
Back to top |
|
 |
arunsenthild |
Posted: Wed Feb 13, 2008 1:11 am Post subject: |
|
|
Novice
Joined: 24 Dec 2007 Posts: 11
|
Hi i used the following function to remove message, i've used the message selector and everything correct even the message is not getting deleted.
public void remMess(String remQueue,String corelId)
{
QueueBrowser browser = null;
QueueReceiver receiver = null;
TextMessage message = null;
QueueConnectionFactory factory = null;
QueueConnection connection = null;
QueueSession l_session = null;
try
{
String l_initContextFactory = getInitialContextFactory();
String l_providerUrl = getProviderUrl();
String l_QCF = getConnectionFactory();
Properties l_properties = new Properties();
l_properties.put(Context.PROVIDER_URL, l_providerUrl);
l_properties.put(
Context.INITIAL_CONTEXT_FACTORY,
l_initContextFactory);
InitialContext l_initContext = new InitialContext(l_properties);
factory =
(QueueConnectionFactory) l_initContext.lookup(l_QCF);
connection = factory.createQueueConnection();
connection.start();
l_session = connection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) l_initContext.lookup(remQueue);
String messageSelector = "JMSCorrelationID ='" + corelId + "'";
browser = l_session.createBrowser(queue);
receiver = l_session.createReceiver(queue,messageSelector);
connection.start();
}
catch (NamingException ne)
{
ne.printStackTrace();
try
{
receiver.close();
}
catch(JMSException re)
{
re.printStackTrace();
}
}
catch (JMSException e)
{
e.printStackTrace();
try
{
receiver.close();
}
catch(JMSException re1)
{
re1.printStackTrace();
}
}
try
{
for (Enumeration en = browser.getEnumeration();
en.hasMoreElements();
)
{
Object obj = en.nextElement();
Message m = (Message) obj;
if (m != null)
{
if (m instanceof TextMessage)
{
message = (TextMessage) m;
String str3 = message.getJMSCorrelationID();
if (corelId.equals(str3))
{
receiver.receiveNoWait();
l_session.commit();
}
}
else if (m instanceof BytesMessage)
{ messageb = (BytesMessage) m;
String str3 = messageb.getJMSCorrelationID();
if ("NO".equalsIgnoreCase(System.getProperty("IS_JMS_HEADER_SET")))
{
String l_str = str3.substring(str3.indexOf("3"), str3.indexOf("00"));
if(l_str.length() % 2 != 0)
{
l_str += "0";
}
try
{
l_str = hexStrToActual(l_str);
str3 = l_str;
}
catch (Exception fmte)
{
}
}
if (corelId.equals(str3))
{
try
{
receiver.receiveNoWait();
l_session.commit();
}
catch(JMSException j)
{
}
}
}
else
{
break;
}
}
else
{
}
}
}
catch (JMSException e)
{
try
{
l_session.rollback();
}
catch(JMSException e1)
{
}
}
finally
{
try
{
if(connection!=null)
connection.stop();
if(l_session!=null)
l_session.close();
if(connection!=null)
connection.close();
receiver.close();
browser.close();
}
catch (JMSException e)
{
e.printStackTrace();
}
}
} |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Feb 13, 2008 3:38 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Did you try closing the queue browser before running the receiver.receive?
Do you get any exception thrown? what is the linked exception?
What is the client version and server version? What are the platforms involved? (hardware/os)
What is the input count on the queue?
Does a second run of the program show the same message? (msgid and correlid)? _________________ MQ & Broker admin |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Feb 13, 2008 4:39 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Why are you using a QueueBrowser in the first place? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
arunsenthild |
Posted: Wed Feb 13, 2008 5:25 am Post subject: |
|
|
Novice
Joined: 24 Dec 2007 Posts: 11
|
Now i used browser.close before
receiver.receiveNoWait();
l_session.commit();
No exceptions are thron i've checked by veryfing the logs
Now also i'm not able to remove the message from the queue.
i'm able to get the corelation id too.
The message never gets deleted. It remains in the queue
@jefflowrey
I'm using this browser, cos to browse the messages and delete it.
If u have a different method please tell me that also.
 |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Feb 13, 2008 5:32 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Do you want to leave any messages on the queue?
If not, then don't browse. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Feb 13, 2008 2:49 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
fjb_saper wrote: |
What is the client version and server version? What are the platforms involved? (hardware/os)
What is the input count on the queue?
Does a second run of the program show the same message? (msgid and correlid)? |
Do all messages on the queue have the same correlationId??
If the answer to the previous question does not show the error of your ways, it is PMR time...
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|