使用Java和AMQP 1.0消息大小问题的Windows Server(1.1)上的Service Bus

时间:2017-04-04 11:00:44

标签: java windows service amqp bus

我们正在使用AMQP jar以下的邮件将邮件从java发送到Windows服务器(1.1)上的服务总线中的队列设置。发送小消息但无法发送前期大小超过45kb,生成160kb的消息没有问题。消息根本没有命中队列,java端也没有例外。

的geronimo-jms_1.1_spec-1.0.1.jar qpid-AMQP-1-0-客户0.22.jar qpid-AMQP-1-0-客户JMS-0.22.jar qpid-AMQP-1-0-共0.22.jar

在网关配置中正确配置了已接收消息。

                                                      

我只是想知道导致此邮件大小限制的原因是什么?任何帮助将不胜感激。

谢谢你, 斯里兰卡。

2 个答案:

答案 0 :(得分:0)

这是我编写的用于发送一条消息(109 kb)的小型测试程序。我没有在java端获得任何异常,并且消息也没有出现在服务总线队列中。

import org.apache.qpid.amqp_1_0.jms.impl.*;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.net.URLEncoder;
import java.util.Hashtable;
import java.io.*;

public class ServiceBusPublisher {

public static void main(String[] args) throws Exception {               
    String userName = "test";
    String password = "test";       
    String fqdn = "test@test.com";

    String connectionString = "amqps://" + encode(userName) + ":" + encode(password) + "@" + fqdn;


        File file = new File("D:\\temp\\test.xml");
    FileReader fileReader = new FileReader(file);
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    StringBuffer stringBuffer = new StringBuffer();
    String line;
    while ((line = bufferedReader.readLine()) != null) {
        stringBuffer.append(line);
        stringBuffer.append("\n");
    }
    bufferedReader.close();
    fileReader.close();

    String messageText = stringBuffer.toString();         

    System.out.print("Initial setup\n");
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
        env.put(Context.PROVIDER_URL, "blah.txt");
        env.put("connectionfactory.ServiceBusConnectionFactory", connectionString);
        Context context = null;
        ConnectionFactory connectionFactory = null;
        Connection connection = null;
        try
        {
            System.out.print("Creating context\n");
            context = new InitialContext(env);
            System.out.print("Creating connection factory\n");
            connectionFactory = (ConnectionFactory)context.lookup("ServiceBusConnectionFactory");
            System.out.print("Creating connection\n");
            connection = connectionFactory.createConnection();
        }
        catch (Exception e)
        {
            System.out.print("Exception creating context/connection factory/connection\n");
            System.out.print(e.toString());
            return;
        }

        Session session = null;
        MessageProducer producer = null;
        try
        {
            System.out.print("Creating session\n");
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            System.out.print("Creating producer\n");
            producer = session.createProducer(QueueImpl.createQueue("MessageProcessingService-PRE/testqueue"));                                                        
        }
        catch (Exception e)
        {
            System.out.print("Exception creating session/producer\n");
            System.out.print(e.toString());
            return;
        }

        try
        {
            System.out.print("Creating message\n");
            BytesMessage message = session.createBytesMessage();                
            message.writeBytes(messageText.getBytes("UTF-8"));              
            message.setStringProperty("JMSXGroupID", "MessageProcessingService-PRE/testqueue");
            System.out.print("Sending\n");
            producer.send(message);             
        }
        catch (Exception e)
        {
            System.out.print("Exception creating message and sending\n");
            System.out.print(e.toString());
            return;
        }           

        try
        {
            System.out.print("Cleaning up\n");
            producer.close();
            session.close();
            connection.stop();
            connection.close();
        }
        catch (Exception e)
        {
            System.out.print("Exception closing producer and session\n");
            System.out.print(e.toString());
        }
}

public static String encode(String encodee)
    {
        String retval = "";
        try { retval = URLEncoder.encode(encodee, "UTF-8"); } catch (Exception e) { System.out.print("Encoding failed\n"); }
        return retval;
    }

}

答案 1 :(得分:0)

我有同样的问题。无法发送大于256kb的消息。出现错误链接已分离。

问题出在服务总线的配置中。默认情况下,SB不允许大于256kb的消息。我们必须更改配置以允许更大的消息。