0

以下は私の消費者です:

 public static void main(String[] args) throws JMSException {
        // Getting JMS connection from the server
        ConnectionFactory connectionFactory
            = new ActiveMQConnectionFactory(url);
        Connection connection = connectionFactory.createConnection();
        connection.start();

        // Creating session for seding messages
        Session session = connection.createSession(false,
            Session.AUTO_ACKNOWLEDGE);

        // Getting the queue 'TESTQUEUE'
        Destination destination = session.createQueue(subject);

        // MessageConsumer is used for receiving (consuming) messages
        MessageConsumer consumer = session.createConsumer(destination);

        // Here we receive the message.
        // By default this call is blocking, which means it will wait
        // for a message to arrive on the queue.
        Message message = consumer.receive();
        System.out.println(message);


     // There are many types of Message and TextMessage
        // is just one of them. Producer sent us a TextMessage
        // so we must cast to it to get access to its .getText()
        // method.
        if(message instanceof ObjectMessage){
            ObjectMessage objectMessage  = (ObjectMessage)message;
            System.out.println(" Received Message : '"+objectMessage.getObject()+" '");
        }

        connection.close();
    }

キューには 10 件のメッセージがあります。
現在、各コンシューマによって 1 つのメッセージが消費されます。各コンシューマーが 10 個のメッセージを消費するようにします。
そのためには、どのような変更を行う必要がありますか?

4

1 に答える 1

1

キューの性質は、1 つのプロデューサーと 1 つのコンシューマーを持つことです。これにはトピックを使用する必要があります。

于 2012-06-21T10:41:52.250 に答える