admin
2020-10-26 89e370bfdda29ac8a8f7080a18dc09a6ddc75c09
src/main/java/com/yeshi/buwan/util/mq/CMQUtil.java
@@ -95,10 +95,8 @@
    * 指定参数创建队列
    * 
    * @param queueName
    * @param pollingWaitSeconds
    *            -长轮训等待时间
    * @param visibilityTimeout
    *            -消息消费后再次可见的时间
     * @param pollingWaitSeconds -长轮训等待时间
     * @param visibilityTimeout  -消息消费后再次可见的时间
    * @return
    */
   public boolean createQueue(String queueName, int pollingWaitSeconds, int visibilityTimeout) {
@@ -109,6 +107,7 @@
      meta.maxMsgSize = 65536;
      meta.msgRetentionSeconds = 345600;
      try {
//            if (account.getQueue(queueName) != null)
         account.createQueue(queueName, meta);
         return true;
      } catch (Exception e) {
@@ -184,10 +183,8 @@
   /**
    * 消费消息
    * 
    * @param count
    *            1-16
    * @param queueName
    *            队列名字
     * @param count     1-16
     * @param queueName 队列名字
    * @return
    */
   public List<Message> recieveMsg(int count, String queueName) {
@@ -245,6 +242,7 @@
    */
   public boolean createTopic(String topicName, int maxMsgSize, int filterType) {
      try {
//            if (topicAccount.getTopic(topicName) == null)
         topicAccount.createTopic(topicName, maxMsgSize, filterType);
         return true;
      } catch (Exception e) {
@@ -261,6 +259,7 @@
    */
   public boolean createTopic(String topicName) {
      try {
            if (topicAccount.getTopic(topicName) == null)
         topicAccount.createTopic(topicName, 65536);
         return true;
      } catch (Exception e) {
@@ -280,6 +279,27 @@
   public boolean subscribeTopic(String topicName, String subscriptionName, String queueName) {
      try {
         topicAccount.createSubscribe(topicName, subscriptionName, queueName, "queue");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    /**
     * 订阅
     *
     * @param topicName
     * @param subscriptionName
     * @param queueName
     * @param filterTag
     * @return
     */
    public boolean subscribeTopic(final String topicName, final String subscriptionName, String queueName,
                                  final List<String> filterTag) {
        try {
            topicAccount.createSubscribe(topicName, subscriptionName, queueName, "queue",
                    filterTag, null, null, null);
            return true;
      } catch (Exception e) {
         e.printStackTrace();
      }
@@ -324,6 +344,27 @@
      return false;
   }
    /**
     * 发布订阅消息
     * @param topicName
     * @param message
     * @param tags
     * @return
     */
    public boolean publishTopicMessage(String topicName, String message, List<String> tags) {
        try {
            Topic topic = topicAccount.getTopic(topicName);
            if (topic == null)
                return false;
            topic.publishMessage(message, tags, null);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
   /**
    * 批量发布消息
    *