You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Li Li <fa...@gmail.com> on 2014/03/03 11:39:51 UTC

can I enable queue priority by plain java code

as in http://activemq.apache.org/how-can-i-support-priority-queues.html,
I should enable queue priority by xml configuration. is it possible to
use java api to configure this?

Re: can I enable queue priority by plain java code

Posted by Li Li <fa...@gmail.com>.
I know how to set priority for a message, what I want is enable
priority of broker when create a queue using java client api.

On Tue, Mar 4, 2014 at 3:08 PM, Noel OConnor <no...@gmail.com> wrote:
> http://docs.oracle.com/javaee/5/api/javax/jms/MessageProducer.html#setPriority(int)
>
>
> On Tue, Mar 4, 2014 at 11:57 AM, Li Li <fa...@gmail.com> wrote:
>
>> I am using the following code snippet to send messages to a queue. How
>> to make priority queue enabled?
>> class Producer{
>> private ActiveMQConnection conn;
>> private QueueSender sender;
>> private QueueSession session;
>> public Producer() throws JMSException{
>> ActiveMQConnectionFactory connectionFactory = new
>> ActiveMQConnectionFactory(
>> "tcp://localhost:61616");
>> conn = (ActiveMQConnection) connectionFactory.createConnection();
>> conn.start();
>>    session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
>>
>>     Queue queue = session.createQueue("TEST.QUEUE");
>>
>> sender = session.createSender(queue);
>> sender.setDeliveryMode(DeliveryMode.PERSISTENT);
>> }
>> public void sendMsgs(int max) throws JMSException{
>> //sender.setTimeToLive(10000);
>> for(int i=0;i<max;i++){
>> Message msg=session.createTextMessage("msg"+i);
>> sender.send(msg);
>> }
>> }
>> public void close(){
>> if(this.session!=null){
>> try {
>> session.close();
>> } catch (JMSException e) {
>> e.printStackTrace();
>> }
>> }
>> if(this.conn!=null){
>> try {
>> this.conn.close();
>> } catch (JMSException e) {
>> e.printStackTrace();
>> }
>> }
>> }
>> }
>>
>> On Mon, Mar 3, 2014 at 9:59 PM, Christian Posta
>> <ch...@gmail.com> wrote:
>> > If you build your broker using the java API you can do this by
>> > creating the policy entry and using its setters directly.
>> >
>> > Is that what you're asking? Otherwise you set the priority on a
>> > message by using the JMS APIs.
>> >
>> > On Mon, Mar 3, 2014 at 3:39 AM, Li Li <fa...@gmail.com> wrote:
>> >> as in http://activemq.apache.org/how-can-i-support-priority-queues.html
>> ,
>> >> I should enable queue priority by xml configuration. is it possible to
>> >> use java api to configure this?
>> >
>> >
>> >
>> > --
>> > Christian Posta
>> > http://www.christianposta.com/blog
>> > twitter: @christianposta
>>

Re: can I enable queue priority by plain java code

Posted by Noel OConnor <no...@gmail.com>.
http://docs.oracle.com/javaee/5/api/javax/jms/MessageProducer.html#setPriority(int)


On Tue, Mar 4, 2014 at 11:57 AM, Li Li <fa...@gmail.com> wrote:

> I am using the following code snippet to send messages to a queue. How
> to make priority queue enabled?
> class Producer{
> private ActiveMQConnection conn;
> private QueueSender sender;
> private QueueSession session;
> public Producer() throws JMSException{
> ActiveMQConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory(
> "tcp://localhost:61616");
> conn = (ActiveMQConnection) connectionFactory.createConnection();
> conn.start();
>    session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
>
>     Queue queue = session.createQueue("TEST.QUEUE");
>
> sender = session.createSender(queue);
> sender.setDeliveryMode(DeliveryMode.PERSISTENT);
> }
> public void sendMsgs(int max) throws JMSException{
> //sender.setTimeToLive(10000);
> for(int i=0;i<max;i++){
> Message msg=session.createTextMessage("msg"+i);
> sender.send(msg);
> }
> }
> public void close(){
> if(this.session!=null){
> try {
> session.close();
> } catch (JMSException e) {
> e.printStackTrace();
> }
> }
> if(this.conn!=null){
> try {
> this.conn.close();
> } catch (JMSException e) {
> e.printStackTrace();
> }
> }
> }
> }
>
> On Mon, Mar 3, 2014 at 9:59 PM, Christian Posta
> <ch...@gmail.com> wrote:
> > If you build your broker using the java API you can do this by
> > creating the policy entry and using its setters directly.
> >
> > Is that what you're asking? Otherwise you set the priority on a
> > message by using the JMS APIs.
> >
> > On Mon, Mar 3, 2014 at 3:39 AM, Li Li <fa...@gmail.com> wrote:
> >> as in http://activemq.apache.org/how-can-i-support-priority-queues.html
> ,
> >> I should enable queue priority by xml configuration. is it possible to
> >> use java api to configure this?
> >
> >
> >
> > --
> > Christian Posta
> > http://www.christianposta.com/blog
> > twitter: @christianposta
>

Re: can I enable queue priority by plain java code

Posted by Li Li <fa...@gmail.com>.
I am using the following code snippet to send messages to a queue. How
to make priority queue enabled?
class Producer{
private ActiveMQConnection conn;
private QueueSender sender;
private QueueSession session;
public Producer() throws JMSException{
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
"tcp://localhost:61616");
conn = (ActiveMQConnection) connectionFactory.createConnection();
conn.start();
   session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    Queue queue = session.createQueue("TEST.QUEUE");

sender = session.createSender(queue);
sender.setDeliveryMode(DeliveryMode.PERSISTENT);
}
public void sendMsgs(int max) throws JMSException{
//sender.setTimeToLive(10000);
for(int i=0;i<max;i++){
Message msg=session.createTextMessage("msg"+i);
sender.send(msg);
}
}
public void close(){
if(this.session!=null){
try {
session.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
if(this.conn!=null){
try {
this.conn.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
}
}

On Mon, Mar 3, 2014 at 9:59 PM, Christian Posta
<ch...@gmail.com> wrote:
> If you build your broker using the java API you can do this by
> creating the policy entry and using its setters directly.
>
> Is that what you're asking? Otherwise you set the priority on a
> message by using the JMS APIs.
>
> On Mon, Mar 3, 2014 at 3:39 AM, Li Li <fa...@gmail.com> wrote:
>> as in http://activemq.apache.org/how-can-i-support-priority-queues.html,
>> I should enable queue priority by xml configuration. is it possible to
>> use java api to configure this?
>
>
>
> --
> Christian Posta
> http://www.christianposta.com/blog
> twitter: @christianposta

Re: can I enable queue priority by plain java code

Posted by Christian Posta <ch...@gmail.com>.
If you build your broker using the java API you can do this by
creating the policy entry and using its setters directly.

Is that what you're asking? Otherwise you set the priority on a
message by using the JMS APIs.

On Mon, Mar 3, 2014 at 3:39 AM, Li Li <fa...@gmail.com> wrote:
> as in http://activemq.apache.org/how-can-i-support-priority-queues.html,
> I should enable queue priority by xml configuration. is it possible to
> use java api to configure this?



-- 
Christian Posta
http://www.christianposta.com/blog
twitter: @christianposta