jms:无法从消费者那里获得印地文数据

时间:2014-08-20 06:51:07

标签: java utf-8 jms activemq

我已经在java的帮助下设置了activemq来实现jms。我为Producer和Consumer编写了简单的程序。我可以发送印地文数据(UTF-8)数据。但是当我试图接收utf-8数据消息时,获取垃圾数据。我有点混淆设置字符编码的位置。

制片人发送 - “हैलोरोहित”

消费者接收 - “????? ??????” (UTF-8问题)。 我正在丢失数据的字符编码。如何申请或获取UTF-8数据。

注意:xx.xx.xx.xx:8161 / admin如果浏览我可以看到我创建的每个队列的状态。即使那个印地文消息也恰到好处。

生产者代码的快照:

public static void main(String[] args) {
    ConnectionFactory connectionFactory =
        new ActiveMQConnectionFactory("user", "password", "tcp://xx.xx.xx.xxx:61616");
    Connection connection = connectionFactory.createConnection();
    connection.start();
    Session session = connection.createSession(false,
        Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue("NewQueue");
    MessageProducer producer = session.createProducer(destination);
    TextMessage message = session.createTextMessage("हैलो रोहित");
    producer.send(message);
    System.out.println("Sent message '" + message.getText() + "'");
    connection.close();
}

消费者代码快照:

 public static void main(String[] args) throws JMSException {
   // Getting JMS connection from the server
   ConnectionFactory connectionFactory
        = new ActiveMQConnectionFactory("user", "password", "tcp://xx.xxx.xx.xxx:61616");
    Connection connection = connectionFactory.createConnection();
    connection.start();
    // Creating session for sending messages
    Session session = connection.createSession(false,
        Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue("NewQueue");
    // MessageConsumer is used for receiving (consuming) messages
    MessageConsumer consumer = session.createConsumer(destination);
    Message message = consumer.receive();
    if (message instanceof TextMessage) {
        TextMessage textMessage = (TextMessage) message;
        System.out.println("Received message '"
            + textMessage.getText() + "'");
    }
    connection.close();
}

0 个答案:

没有答案