You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by CallMeXYZ <am...@gmail.com> on 2016/10/27 07:28:50 UTC

scheduler message deliver immediately

I'm using ActiveMQ with Spring , I have set the /SchedulerSupport / but seems
not to work.
Below is my configuration.
============================
@Configuration
@EnableJms
public class MessageConfig {
    private static final String DEFAULT_BROKER_URL =
"tcp://localhost:61616";

    public static final String DESTINATION_FB = "fb";
    private static final String USER_NAME = "admin";
    private static final String USER_PASSWORD = "admin";
    @Profile("embedded")
    @Bean(initMethod = "start", destroyMethod = "stop")
    public BrokerService brokerService() throws Exception {
        BrokerService brokerService = new BrokerService();
        brokerService.setSchedulerSupport(true);
        brokerService.addConnector(DEFAULT_BROKER_URL);
        return brokerService;
    }
    @Bean
    public ConnectionFactory connectionFactory() {
        ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory();
       connectionFactory.setBrokerURL(DEFAULT_BROKER_URL);
         /*  connectionFactory.setUserName(USER_NAME);
        connectionFactory.setPassword(USER_PASSWORD);*/
        connectionFactory.setTrustedPackages(Arrays.asList("com.test.test",
"java.lang"));
        return connectionFactory;
    }

    @Bean
    public JmsTemplate jmsTemplate(ConnectionFactory factory) {
        JmsTemplate template = new JmsTemplate();
        template.setConnectionFactory(factory);
        template.setDefaultDestinationName(DESTINATION_FB);
        return template;
    }
    @Bean
    public DefaultMessageListenerContainer
jmsListenerContainerFactory(ConnectionFactory connectionFactory){
        DefaultMessageListenerContainer containerFactory = new
DefaultMessageListenerContainer();
        containerFactory.setConnectionFactory(connectionFactory);
        return containerFactory;
    }
}
========Sender============
@Component
public class MessageSender {
    @Autowired
    JmsTemplate jmsTemplate;
    public void sendMessage(final ResultCode data) {

        jmsTemplate.send(new MessageCreator(){
            @Override
            public Message createMessage(Session session) throws
JMSException {
                ObjectMessage objectMessage =
session.createObjectMessage(data);
               
objectMessage.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY,600000);
                return objectMessage;
            }
        });
    }
}
=======Receiver=====
@Component
public class MessageReceiver {

    @JmsListener(destination = MessageConfig.DESTINATION_FB)

    public void receiveMessage(ResultCode data) {
        System.out.println("Received <" + data.getInfo() + ">");
    }

}


Thanks for your reading



--
View this message in context: http://activemq.2283324.n4.nabble.com/scheduler-message-deliver-immediately-tp4718568.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: scheduler message deliver immediately

Posted by CallMeXYZ <am...@gmail.com>.
got it sry,thanks



--
View this message in context: http://activemq.2283324.n4.nabble.com/scheduler-message-deliver-immediately-tp4718568p4718574.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: scheduler message deliver immediately

Posted by Rob Davies <ra...@gmail.com>.
I mean start the broker outside your code, run it standalone :)

> On 27 Oct 2016, at 10:05, CallMeXYZ <am...@gmail.com> wrote:
> 
> how can i  get scheduler support without broker? I thought it should be
> configured inside broker
> 
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/scheduler-message-deliver-immediately-tp4718568p4718572.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: scheduler message deliver immediately

Posted by CallMeXYZ <am...@gmail.com>.
how can i  get scheduler support without broker? I thought it should be
configured inside broker



--
View this message in context: http://activemq.2283324.n4.nabble.com/scheduler-message-deliver-immediately-tp4718568p4718572.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: scheduler message deliver immediately

Posted by CallMeXYZ <am...@gmail.com>.
ActiveMQ has installed as a service. Restart my PC,and do nothing.And check
the port using n/netstat -ano|findstr "61616"/.I got
/ TCP    0.0.0.0:61616          0.0.0.0:0              LISTENING       1820
 TCP    [::]:61616             [::]:0                 LISTENING       1820/
And if the process was killed through /taskkill /pid portNumber /F/
manually, it will restart in another pid quickly.

PS:I'm programming using IDEA with tomcat as a server.Sure that the tomcat
was not running when checking the port.



--
View this message in context: http://activemq.2283324.n4.nabble.com/scheduler-message-deliver-immediately-tp4718568p4718848.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: scheduler message deliver immediately

Posted by Tim Bain <tb...@alumni.duke.edu>.
That error means either 1) an ActiveMQ broker is already running on that
host, or 2) your configuration somehow causes you to start two brokers.
The web console you're connecting to is the one for that other broker,
which is why you see no activity.

When your broker is stopped and you issue a netstat -a | grep 61616, what
response do you get?

On Nov 1, 2016 8:02 PM, "CallMeXYZ" <am...@gmail.com> wrote:

> I do understand the web console take the localhost:8161.But I always get
> 'java.net.BindException: Address already in use: JVM_Bind exception. ' if
> my
> broker url is 61616.
>  Either I change my broker url to 61617 or change the activemq.xml
> configuration /<transportConnector name="openwire"
> uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;
> wireFormat.maxFrameSize=104857600"/>/
> to /tcp://0.0.0.0:61616/,then the exception disappears and ActiveMQ works
> while just the web console cannot get my broker infos.(That's why I assume
> that web console may take the 61616 port of broker)
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.
> nabble.com/scheduler-message-deliver-immediately-tp4718568p4718785.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: scheduler message deliver immediately

Posted by CallMeXYZ <am...@gmail.com>.
I do understand the web console take the localhost:8161.But I always get
'java.net.BindException: Address already in use: JVM_Bind exception. ' if my
broker url is 61616.
 Either I change my broker url to 61617 or change the activemq.xml
configuration /<transportConnector name="openwire"
uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>/
to /tcp://0.0.0.0:61616/,then the exception disappears and ActiveMQ works
while just the web console cannot get my broker infos.(That's why I assume
that web console may take the 61616 port of broker)



--
View this message in context: http://activemq.2283324.n4.nabble.com/scheduler-message-deliver-immediately-tp4718568p4718785.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: scheduler message deliver immediately

Posted by Tim Bain <tb...@alumni.duke.edu>.
The web console is typically configured to use port 8161 (see
http://activemq.apache.org/web-console.html) unless you've changed it.  Are
you saying you access the web console on 61616?

When you shut down your broker, can you access the web console?

You may want to post your configuration.

On Oct 31, 2016 8:02 PM, "CallMeXYZ" <am...@gmail.com> wrote:

> Yes,the web console runs and show no activity. I thought it was because my
> broker takes the port of '616167' and the web console listens '61616'.
> Right?Sure that only one broker.the broker and web console cannot have the
> same port
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.
> nabble.com/scheduler-message-deliver-immediately-tp4718568p4718714.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: scheduler message deliver immediately

Posted by CallMeXYZ <am...@gmail.com>.
Yes,the web console runs and show no activity. I thought it was because my
broker takes the port of '616167' and the web console listens '61616'.
Right?Sure that only one broker.the broker and web console cannot have the
same port



--
View this message in context: http://activemq.2283324.n4.nabble.com/scheduler-message-deliver-immediately-tp4718568p4718714.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: scheduler message deliver immediately

Posted by Tim Bain <tb...@alumni.duke.edu>.
If "the web console no longer can monitor the statistics" means that the
console runs but shows no evidence of activity even though you're producing
and consuming messages, then it may be that you're still running a second
broker as Rob guessed last week.  Can you confirm that no other broker is
running on that host?

Tim

On Oct 31, 2016 12:43 AM, "CallMeXYZ" <am...@gmail.com> wrote:

> It's fine when i change my broker url  such as 61617,but the web console no
> longer can monitor the statistics. if i change the ActiveMQ config of
> transportConnector,it throws the same exception again.
> How can i let web console work again?
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.
> nabble.com/scheduler-message-deliver-immediately-tp4718568p4718671.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: scheduler message deliver immediately

Posted by CallMeXYZ <am...@gmail.com>.
It's fine when i change my broker url  such as 61617,but the web console no
longer can monitor the statistics. if i change the ActiveMQ config of
transportConnector,it throws the same exception again.
How can i let web console work again?



--
View this message in context: http://activemq.2283324.n4.nabble.com/scheduler-message-deliver-immediately-tp4718568p4718671.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: scheduler message deliver immediately

Posted by Rob Davies <ra...@gmail.com>.
seems like you either have a running broker from a previous test - or you are creating multiple brokers from changing the config. Search for the activemq process and kill it. I might be easier initially to not create an embedded broker, but start it as a separate process

> On 27 Oct 2016, at 09:38, CallMeXYZ <am...@gmail.com> wrote:
> 
> in fact if i remove the annotations  /@Profile("embedded")/ of/
> brokerService/,i will get a /java.net.BindException: Address already in use:
> JVM_Bind/ exception. why
> 
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/scheduler-message-deliver-immediately-tp4718568p4718570.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: scheduler message deliver immediately

Posted by CallMeXYZ <am...@gmail.com>.
in fact if i remove the annotations  /@Profile("embedded")/ of/
brokerService/,i will get a /java.net.BindException: Address already in use:
JVM_Bind/ exception. why



--
View this message in context: http://activemq.2283324.n4.nabble.com/scheduler-message-deliver-immediately-tp4718568p4718570.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: scheduler message deliver immediately

Posted by Rob Davies <ra...@gmail.com>.
Can’t spot any  gottchas. Could you set the Scheduler directory for your embedded broker - just to check its actually being created ? - see https://github.com/apache/activemq/blob/master/activemq-unit-tests/src/test/java/org/apache/activemq/broker/scheduler/JobSchedulerTestSupport.java#L100 for inspiration


> On 27 Oct 2016, at 08:28, CallMeXYZ <am...@gmail.com> wrote:
> 
> I'm using ActiveMQ with Spring , I have set the /SchedulerSupport / but seems
> not to work.
> Below is my configuration.
> ============================
> @Configuration
> @EnableJms
> public class MessageConfig {
>    private static final String DEFAULT_BROKER_URL =
> "tcp://localhost:61616";
> 
>    public static final String DESTINATION_FB = "fb";
>    private static final String USER_NAME = "admin";
>    private static final String USER_PASSWORD = "admin";
>    @Profile("embedded")
>    @Bean(initMethod = "start", destroyMethod = "stop")
>    public BrokerService brokerService() throws Exception {
>        BrokerService brokerService = new BrokerService();
>        brokerService.setSchedulerSupport(true);
>        brokerService.addConnector(DEFAULT_BROKER_URL);
>        return brokerService;
>    }
>    @Bean
>    public ConnectionFactory connectionFactory() {
>        ActiveMQConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory();
>       connectionFactory.setBrokerURL(DEFAULT_BROKER_URL);
>         /*  connectionFactory.setUserName(USER_NAME);
>        connectionFactory.setPassword(USER_PASSWORD);*/
>        connectionFactory.setTrustedPackages(Arrays.asList("com.test.test",
> "java.lang"));
>        return connectionFactory;
>    }
> 
>    @Bean
>    public JmsTemplate jmsTemplate(ConnectionFactory factory) {
>        JmsTemplate template = new JmsTemplate();
>        template.setConnectionFactory(factory);
>        template.setDefaultDestinationName(DESTINATION_FB);
>        return template;
>    }
>    @Bean
>    public DefaultMessageListenerContainer
> jmsListenerContainerFactory(ConnectionFactory connectionFactory){
>        DefaultMessageListenerContainer containerFactory = new
> DefaultMessageListenerContainer();
>        containerFactory.setConnectionFactory(connectionFactory);
>        return containerFactory;
>    }
> }
> ========Sender============
> @Component
> public class MessageSender {
>    @Autowired
>    JmsTemplate jmsTemplate;
>    public void sendMessage(final ResultCode data) {
> 
>        jmsTemplate.send(new MessageCreator(){
>            @Override
>            public Message createMessage(Session session) throws
> JMSException {
>                ObjectMessage objectMessage =
> session.createObjectMessage(data);
> 
> objectMessage.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY,600000);
>                return objectMessage;
>            }
>        });
>    }
> }
> =======Receiver=====
> @Component
> public class MessageReceiver {
> 
>    @JmsListener(destination = MessageConfig.DESTINATION_FB)
> 
>    public void receiveMessage(ResultCode data) {
>        System.out.println("Received <" + data.getInfo() + ">");
>    }
> 
> }
> 
> 
> Thanks for your reading
> 
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/scheduler-message-deliver-immediately-tp4718568.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.