You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by mruan <mi...@ab-ovo.com> on 2011/04/28 16:19:41 UTC

How to send a textMessage to an exising queue (destination)

I’m new here!

I am using activeMQ-CPP to develop an application in C++.

As you may know that we can send a textMessage to an queue, in most case we
use the following code:


-        Destination *destination = session->createQueue("queueName");

-        MessageProducer *producer = session->createProducer(destination);

-        TextMessage *message = session->createTextMessage( "some text");

-        Producer->send(message);

My question is: how can we send a textMessage to an existing queue
(destination)? In other words: the queue ("queueName") exists already, and
it must NOT be created again! So I just want to send a textMessage to it
without first to create it. 

Thanks in advance

Ming
P.S.
“If the queue exist, messages are sent to the same queue "queueName", what
are your symptons?”

	Then we see the messages arrived indeed in the queue “queueName”, that
will be OK in this case.

The trouble is when the queue “queueName” does NOT exist, a new queue named
“queueName” will be created and this is NOT what I want!
I want that in this case the program will return me a “null” point so that I
know that there are something wrong.

Our project demands that no new queues maybe created.




--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-send-a-textMessage-to-an-exising-queue-destination-tp3481137p3481137.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to send a textMessage to an exising queue (destination)

Posted by Aleksandar Ivanisevic <al...@ivanisevic.de>.
mruan <mi...@ab-ovo.com> writes:

> Thanks Aleksandar! Tim suggested similar solution yesterday, and I tried ...
> I'll try again. Now I hope that you guys understand what I want, and do you
> still think that nobody needs to do like this?

Unfortunately, very few programmers think like you do. If they mistype
a name and it gets missed and the overflowing queue crashes the broker
or whatnot, this will be an ops problem, not theirs.

I'm primarily an admin so my brokers are set like you want to do it,
but when I try to explain it to programmers all I get are blank
stares.

[...]



Re: How to send a textMessage to an exising queue (destination)

Posted by mruan <mi...@ab-ovo.com>.
Thanks Aleksandar! Tim suggested similar solution yesterday, and I tried ...
I'll try again. Now I hope that you guys understand what I want, and do you
still think that nobody needs to do like this? The new suggestions of Tim
seem OK to me as well, though they are new for me, I'll try them as well. In
summary I'll try the following:

1) the destinations + security config.
2) advisory message
3) cache the destination (this is really new, could you provide more info?)

Thanks a lot and I'll report the results next week.

Have a nice weekend.

Ming

--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-send-a-textMessage-to-an-exising-queue-destination-tp3481137p3483919.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to send a textMessage to an exising queue (destination)

Posted by Aleksandar Ivanisevic <al...@ivanisevic.de>.
mruan <mi...@ab-ovo.com> writes:

> What I want is to modify some code (e.g. built-in checks) in the function
> f() so that when the second case happens, the function will NOT create the
> wrong queue.
>
> I hope that I am now clear to you.

You will have to precreate the destinations
(http://activemq.apache.org/configure-startup-destinations.html) and
then set up security with anonymous user enabled and then disallow
creation of new destinations for the anonymous (admin right)
(http://activemq.apache.org/security.html)


something like this


<broker ...


[...]

       <destinations>
           <queue physicalName="queueA" />
           <topic physicalName="topicA" />


[...]


</broker>

<plugins>


[...]


      <simpleAuthenticationPlugin anonymousAccessAllowed="true">
       <users>
                <authenticationUser username="system"
       password="manager" groups="admin"/>
       </users>
      </simpleAuthenticationPlugin>


     <authorizationPlugin>
        <map>
          <authorizationMap>
            <authorizationEntries>
              <authorizationEntry queue=">" read="anonymous,admin" write="anonymous,admin"  admin="admin" />
              <authorizationEntry topic=">" read="anonymous,admin" write="anonymous,admin"  admin="admin" />
            </authorizationEntries>
          </authorizationMap>
        </map>
      </authorizationPlugin>


[...]


</plugins>



Re: How to send a textMessage to an exising queue (destination)

Posted by Timothy Bish <ta...@gmail.com>.
On Fri, 2011-04-29 at 07:42 -0700, mruan wrote:
> Something like this:
> 
> f(string &queuename, string &text)
> {
> ...
>     if (queueName Existing)  // is it possible to check if a queue exists in
> the session???
>        destination = session->createQueue( queueName );
>     else
> // queue does not exist, something wrong
>        return;
> 
>     producer = session->createProducer( destination );
>     TextMessage* message = session->createTextMessage( textA );
>     producer->send(message);
> ...
> } 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/How-to-send-a-textMessage-to-an-exising-queue-destination-tp3481137p3483843.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.

You could subscribe to advisory messages and track what exists on the
broker in you code somewhere.  Or just cache the destination you created
once and reuse that from then on, really up to you how you manage your
requirements in this area.

See: http://activemq.apache.org/advisory-message.html

Regards

-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/

Connect at CamelOne May 24-26

The Open Source Integration Conference


Re: How to send a textMessage to an exising queue (destination)

Posted by mruan <mi...@ab-ovo.com>.
Something like this:

f(string &queuename, string &text)
{
...
    if (queueName Existing)  // is it possible to check if a queue exists in
the session???
       destination = session->createQueue( queueName );
    else
// queue does not exist, something wrong
       return;

    producer = session->createProducer( destination );
    TextMessage* message = session->createTextMessage( textA );
    producer->send(message);
...
} 

--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-send-a-textMessage-to-an-exising-queue-destination-tp3481137p3483843.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to send a textMessage to an exising queue (destination)

Posted by mruan <mi...@ab-ovo.com>.
"So are you asking why you have to call 'createQueue' on the client side?"
--> YES!

"If I understand what you asking then calling the createQueue doesn't
create a new one if there's already on there that matches the name
you've given it, it just create the local representation of the queue
object so that when you send a message or call receive the client code
knows that you are producing or consuming on."

--> I know that no new queue will be created if there's already one on there
that matches the name you've given it, but this is just the problem: what if
I gave a WRONG name? Then a new queue (with the WRONG queue name) will be
created and messages will be sent to the WRONG queue and this is NOT what I
want.

I put some code here:

In order to send a textMessage "textA" to a queue "queueNameA", I have to do
like this:
...
f(string &queuename, string &text)
{
...
    destination = session->createQueue( queueName );
    producer = session->createProducer( destination );
    TextMessage* message = session->createTextMessage( textA );
    producer->send(message);
...
}

Then I call the function 

f("queueNameA", "textA")
There are no problem at this moment: a queue named as "queueNameA" will be
created and the message with a text "textA" will be sent to this queue. 

But next, I want to send another text "textB" to the same queue, but by
accident I write "queueNameB" in stead of "queueNameA":

f("queueNameB", "textB");

the result will be that the text "textB" will be sent to a new created queue
with name of "queueNameB"!  

What I want is to modify some code (e.g. built-in checks) in the function
f() so that when the second case happens, the function will NOT create the
wrong queue.

I hope that I am now clear to you.

Thanks

Ming




--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-send-a-textMessage-to-an-exising-queue-destination-tp3481137p3483807.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to send a textMessage to an exising queue (destination)

Posted by Timothy Bish <ta...@gmail.com>.
On Fri, 2011-04-29 at 06:40 -0700, mruan wrote:
> Then it's will be very strange indeed that nobody needs to do what I am
> supposed to do. Why do we have to create a queue in order to send a message
> even if the queue exists already?
> 
> I study the faq's carefully which Tim told me to do, but I am sorry that I
> still don't find the solution. Put the problem in another way:
> 
> I don't necessarily have to use asynchronous method, I use "receive" method
> which is synchronous. First time I create a queue and I am able to send
> messages to that queue, but second time because the queue is already there,
> so I must not create it again, just send another messages to the existing
> queue, but I don't know how, nobody?
> 

So are you asking why you have to call 'createQueue' on the client side?

If I understand what you asking then calling the createQueue doesn't
create a new one if there's already on there that matches the name
you've given it, it just create the local representation of the queue
object so that when you send a message or call receive the client code
knows that you are producing or consuming on.  

If that's not it maybe you can express your intent with some code to
make clear what you want the client to do.

Regards

-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/

Connect at CamelOne May 24-26

The Open Source Integration Conference


Re: How to send a textMessage to an exising queue (destination)

Posted by mruan <mi...@ab-ovo.com>.
Then it's will be very strange indeed that nobody needs to do what I am
supposed to do. Why do we have to create a queue in order to send a message
even if the queue exists already?

I study the faq's carefully which Tim told me to do, but I am sorry that I
still don't find the solution. Put the problem in another way:

I don't necessarily have to use asynchronous method, I use "receive" method
which is synchronous. First time I create a queue and I am able to send
messages to that queue, but second time because the queue is already there,
so I must not create it again, just send another messages to the existing
queue, but I don't know how, nobody?

Ming

--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-send-a-textMessage-to-an-exising-queue-destination-tp3481137p3483714.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to send a textMessage to an exising queue (destination)

Posted by Oscar Pernas <os...@pernas.es>.
Hi Ming,

I think that nobody needs to do something like this because, guessing about
your problem, you could be trying to dont allow to send messages to a
queue/topic, if you have no consumer of  the same one? (the consumer creates
the queue/topic). is it? (if I'm wrong sorry)
One of the features of JMS is that is asynchronous, and if you are doing
things like that, you are not using one of the features of the message
oriented systems.

It's only an opinnion :-P


Regards!


2011/4/28 Timothy Bish <ta...@gmail.com>

> On Thu, 2011-04-28 at 07:43 -0700, mruan wrote:
> > Thank you very much! In fact I read a lot of your posts on activeMQ.
> >
> > I'm sorry that I still cannot find the solution by reading the faq. I
> hope
> > that you understand what I want: just send a textMessage to an existing
> > queue, that's it. Now the situation is as follows:
> >
> > - if the queue does exist, no problem, the message is sent to the queue
> > - if the queue does NOT exist, I hope that NO queue will be created and
> > return me a warning of abort.
> >
> > I don't understand:
> >
> > - why nobody needs to do like what I do?
> > - why it is so difficult to do it without creating a queue? (Misrosoft
> > provides two methods: one for sending message to a new queue
> -->createqueue;
> > and one to an existing queue -->openqueue
> >
> > Would you please give me a bit more info? I use the Helloworld.cpp as
> > example.
> >
> > Thanks in advance
> >
>
> Try reading the FAQ entries again, you need to create the destinations
> you want at startup via:
>
> http://activemq.apache.org/configure-startup-destinations.html
>
> Then configure security to disallow those whom you don't want to be able
> to create destinations via:
>
> http://activemq.apache.org/security.html
>
>
> Regards
>
>
> --
> Tim Bish
> ------------
> FuseSource
> Email: tim.bish@fusesource.com
> Web: http://fusesource.com
> Twitter: tabish121
> Blog: http://timbish.blogspot.com/
>
> Connect at CamelOne May 24-26
>
> The Open Source Integration Conference
>
>


-- 
Óscar Pernas Plaza.

Re: How to send a textMessage to an exising queue (destination)

Posted by Timothy Bish <ta...@gmail.com>.
On Thu, 2011-04-28 at 07:43 -0700, mruan wrote:
> Thank you very much! In fact I read a lot of your posts on activeMQ. 
> 
> I'm sorry that I still cannot find the solution by reading the faq. I hope
> that you understand what I want: just send a textMessage to an existing
> queue, that's it. Now the situation is as follows:
> 
> - if the queue does exist, no problem, the message is sent to the queue
> - if the queue does NOT exist, I hope that NO queue will be created and
> return me a warning of abort. 
> 
> I don't understand:
> 
> - why nobody needs to do like what I do?
> - why it is so difficult to do it without creating a queue? (Misrosoft
> provides two methods: one for sending message to a new queue -->createqueue;
> and one to an existing queue -->openqueue
> 
> Would you please give me a bit more info? I use the Helloworld.cpp as
> example.
> 
> Thanks in advance
> 

Try reading the FAQ entries again, you need to create the destinations
you want at startup via:

http://activemq.apache.org/configure-startup-destinations.html

Then configure security to disallow those whom you don't want to be able
to create destinations via:

http://activemq.apache.org/security.html


Regards


-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/

Connect at CamelOne May 24-26

The Open Source Integration Conference


Re: How to send a textMessage to an exising queue (destination)

Posted by mruan <mi...@ab-ovo.com>.
Thank you very much! In fact I read a lot of your posts on activeMQ. 

I'm sorry that I still cannot find the solution by reading the faq. I hope
that you understand what I want: just send a textMessage to an existing
queue, that's it. Now the situation is as follows:

- if the queue does exist, no problem, the message is sent to the queue
- if the queue does NOT exist, I hope that NO queue will be created and
return me a warning of abort. 

I don't understand:

- why nobody needs to do like what I do?
- why it is so difficult to do it without creating a queue? (Misrosoft
provides two methods: one for sending message to a new queue -->createqueue;
and one to an existing queue -->openqueue

Would you please give me a bit more info? I use the Helloworld.cpp as
example.

Thanks in advance

Ming

--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-send-a-textMessage-to-an-exising-queue-destination-tp3481137p3481215.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to send a textMessage to an exising queue (destination)

Posted by Timothy Bish <ta...@gmail.com>.
On Thu, 2011-04-28 at 07:19 -0700, mruan wrote:
> I’m new here!
> 
> I am using activeMQ-CPP to develop an application in C++.
> 
> As you may know that we can send a textMessage to an queue, in most case we
> use the following code:
> 
> 
> -        Destination *destination = session->createQueue("queueName");
> 
> -        MessageProducer *producer = session->createProducer(destination);
> 
> -        TextMessage *message = session->createTextMessage( "some text");
> 
> -        Producer->send(message);
> 
> My question is: how can we send a textMessage to an existing queue
> (destination)? In other words: the queue ("queueName") exists already, and
> it must NOT be created again! So I just want to send a textMessage to it
> without first to create it. 
> 
> Thanks in advance
> 
> Ming
> P.S.
> “If the queue exist, messages are sent to the same queue "queueName", what
> are your symptons?”
> 
> 	Then we see the messages arrived indeed in the queue “queueName”, that
> will be OK in this case.
> 
> The trouble is when the queue “queueName” does NOT exist, a new queue named
> “queueName” will be created and this is NOT what I want!
> I want that in this case the program will return me a “null” point so that I
> know that there are something wrong.
> 
> Our project demands that no new queues maybe created.
> 
> 
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/How-to-send-a-textMessage-to-an-exising-queue-destination-tp3481137p3481137.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.

See this entry from the FAQ:
http://activemq.apache.org/how-do-i-restrict-connections-from-creating-new-queues-or-topics.html

Regards


-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/

Connect at CamelOne May 24-26

The Open Source Integration Conference