// Path: mq-aliyun-core/src/main/java/com/github/mq/core/scan/constant/MqConstant.java
// public interface MqConstant {
//     String ACCESS_KEY = "aliyun.accessKey";
//     String SECRET_KEY = "aliyun.secretKey";
//     String MQ_SUFFIX = "aliyun.mq.suffix";
// 
// }
// 
// Path: mq-aliyun-producer-spring-boot-starter/src/main/java/com/github/mq/producer/ProducerFactory.java
// public interface ProducerFactory {
//     void sendAsync(final Enum address,final Object message);
//     void sendAsync(final Enum address,final Object message, final DeliveryOption deliveryOption);
//     void sendAsync(final Enum address,final Object message, final SendCallback sendCallback);
//     void sendAsync(final Enum address, final Object message, final DeliveryOption deliveryOption, final SendCallback sendCallback);
// 
//     SendResult orderSend(final Enum address, final Object message, final String shardingKey);
//     SendResult orderSend(final Enum address, final Object message, final String shardingKey,final DeliveryOption deliveryOption);
// 
//     Producer getProducer(String pid);
//     OrderProducer getOrderProducer(String pid);
//     void addProducer(String pid);
//     void addOrdereProducer(String pid);
// }
// 
// Path: mq-aliyun-producer-spring-boot-starter/src/main/java/com/github/mq/producer/ProducerSerialize.java
// public interface ProducerSerialize {
// 
//     byte[] objToBytes(Object object);
// }
// 
// Path: mq-aliyun-producer-spring-boot-starter/src/main/java/com/github/mq/producer/models/DeliveryOption.java
// public class DeliveryOption {
//     private String key;
//     private Long deliverTime;
//     public String getKey() {
//         return key;
//     }
// 
//     public DeliveryOption(){}
//     public DeliveryOption(String key){
//         this.key = key;
//     }
// 
//     public DeliveryOption setKey(String key) {
//         this.key = key;
//         return this;
//     }
// 
//     public Long getDeliverTime() {
//         return deliverTime;
//     }
// 
//     public DeliveryOption setDeliverTime(Long deliverTime) {
//         this.deliverTime = deliverTime;
//         return this;
//     }
// }
// 
// Path: mq-aliyun-producer-spring-boot-starter/src/main/java/com/github/mq/producer/models/PendingMsg.java
// public class PendingMsg {
//     private Enum anEnum;
//     private Object message;
//     private DeliveryOption deliveryOption;
//     private SendCallback sendCallback;
// 
//     public PendingMsg(){}
// 
//     public PendingMsg(Enum anEnum,Object message,DeliveryOption deliveryOption,SendCallback sendCallback){
//         this.anEnum =anEnum;
//         this.message = message;
//         this.deliveryOption = deliveryOption;
//         this.sendCallback = sendCallback;
//     }
// 
// 
//     public Enum getAnEnum() {
//         return anEnum;
//     }
// 
//     public void setAnEnum(Enum anEnum) {
//         this.anEnum = anEnum;
//     }
// 
//     public Object getMessage() {
//         return message;
//     }
// 
//     public void setMessage(Object message) {
//         this.message = message;
//     }
// 
//     public DeliveryOption getDeliveryOption() {
//         return deliveryOption;
//     }
// 
//     public void setDeliveryOption(DeliveryOption deliveryOption) {
//         this.deliveryOption = deliveryOption;
//     }
// 
//     public SendCallback getSendCallback() {
//         return sendCallback;
//     }
// 
//     public void setSendCallback(SendCallback sendCallback) {
//         this.sendCallback = sendCallback;
//     }
// }


import com.aliyun.openservices.ons.api.*;
import com.aliyun.openservices.ons.api.order.OrderProducer;
import com.aliyun.openservices.shade.com.alibaba.rocketmq.shade.com.alibaba.fastjson.JSONObject;
import com.github.mq.core.scan.constant.MqConstant;
import com.github.mq.producer.ProducerFactory;
import com.github.mq.producer.ProducerSerialize;
import com.github.mq.producer.models.DeliveryOption;
import com.github.mq.producer.models.PendingMsg;
import com.github.mq.producer.models.Pid;
import com.github.mq.producer.models.To;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import java.util.*;
import static java.lang.Thread.sleep;
        if (null == producer) {
            Boolean isStart = checkStart.get(pid);
            if (null != isStart && !isStart) {
                List<PendingMsg> messages = pendding.get(pid);
                if (null == messages) {
                    messages = new ArrayList<>();
                }
                messages.add(new PendingMsg(address, message, deliveryOption, sendCallback));
                pendding.put(pid,messages);
                return;
            } else {
                throw new RuntimeException(String.format("发送失败, 无效的pid: %s, address: %s", messageBuild.getPid(),address.name()));
            }
        }
        if (!producer.isStarted()) {
            producer.start();
        }
        if (null != sendCallback) {
            producer.sendAsync(messageBuild.getMessage(), sendCallback);
        } else {
            producer.sendOneway(messageBuild.getMessage());
        }
    }

    @Override
    public SendResult orderSend(final Enum address, final Object message, final String shardingKey) {
        return orderSend(address, message, shardingKey, null);
    }

    @Override
// Path: mq-aliyun-core/src/main/java/com/github/mq/core/scan/constant/MqConstant.java
// public interface MqConstant {
//     String ACCESS_KEY = "aliyun.accessKey";
//     String SECRET_KEY = "aliyun.secretKey";
//     String MQ_SUFFIX = "aliyun.mq.suffix";
// 
// }
// 
// Path: mq-aliyun-producer-spring-boot-starter/src/main/java/com/github/mq/producer/ProducerFactory.java
// public interface ProducerFactory {
//     void sendAsync(final Enum address,final Object message);
//     void sendAsync(final Enum address,final Object message, final DeliveryOption deliveryOption);
//     void sendAsync(final Enum address,final Object message, final SendCallback sendCallback);
//     void sendAsync(final Enum address, final Object message, final DeliveryOption deliveryOption, final SendCallback sendCallback);
// 
//     SendResult orderSend(final Enum address, final Object message, final String shardingKey);
//     SendResult orderSend(final Enum address, final Object message, final String shardingKey,final DeliveryOption deliveryOption);
// 
//     Producer getProducer(String pid);
//     OrderProducer getOrderProducer(String pid);
//     void addProducer(String pid);
//     void addOrdereProducer(String pid);
// }
// 
// Path: mq-aliyun-producer-spring-boot-starter/src/main/java/com/github/mq/producer/ProducerSerialize.java
// public interface ProducerSerialize {
// 
//     byte[] objToBytes(Object object);
// }
// 
// Path: mq-aliyun-producer-spring-boot-starter/src/main/java/com/github/mq/producer/models/DeliveryOption.java
// public class DeliveryOption {
//     private String key;
//     private Long deliverTime;
//     public String getKey() {
//         return key;
//     }
// 
//     public DeliveryOption(){}
//     public DeliveryOption(String key){
//         this.key = key;
//     }
// 
//     public DeliveryOption setKey(String key) {
//         this.key = key;
//         return this;
//     }
// 
//     public Long getDeliverTime() {
//         return deliverTime;
//     }
// 
//     public DeliveryOption setDeliverTime(Long deliverTime) {
//         this.deliverTime = deliverTime;
//         return this;
//     }
// }
// 
// Path: mq-aliyun-producer-spring-boot-starter/src/main/java/com/github/mq/producer/models/PendingMsg.java
// public class PendingMsg {
//     private Enum anEnum;
//     private Object message;
//     private DeliveryOption deliveryOption;
//     private SendCallback sendCallback;
// 
//     public PendingMsg(){}
// 
//     public PendingMsg(Enum anEnum,Object message,DeliveryOption deliveryOption,SendCallback sendCallback){
//         this.anEnum =anEnum;
//         this.message = message;
//         this.deliveryOption = deliveryOption;
//         this.sendCallback = sendCallback;
//     }
// 
// 
//     public Enum getAnEnum() {
//         return anEnum;
//     }
// 
//     public void setAnEnum(Enum anEnum) {
//         this.anEnum = anEnum;
//     }
// 
//     public Object getMessage() {
//         return message;
//     }
// 
//     public void setMessage(Object message) {
//         this.message = message;
//     }
// 
//     public DeliveryOption getDeliveryOption() {
//         return deliveryOption;
//     }
// 
//     public void setDeliveryOption(DeliveryOption deliveryOption) {
//         this.deliveryOption = deliveryOption;
//     }
// 
//     public SendCallback getSendCallback() {
//         return sendCallback;
//     }
// 
//     public void setSendCallback(SendCallback sendCallback) {
//         this.sendCallback = sendCallback;
//     }
// }


// Path: mq-aliyun-producer-spring-boot-starter/src/main/java/com/github/mq/producer/impls/ProducerFactoryImpl.java
import com.aliyun.openservices.ons.api.*;
import com.aliyun.openservices.ons.api.order.OrderProducer;
import com.aliyun.openservices.shade.com.alibaba.rocketmq.shade.com.alibaba.fastjson.JSONObject;
import com.github.mq.core.scan.constant.MqConstant;
import com.github.mq.producer.ProducerFactory;
import com.github.mq.producer.ProducerSerialize;
import com.github.mq.producer.models.DeliveryOption;
import com.github.mq.producer.models.PendingMsg;
import com.github.mq.producer.models.Pid;
import com.github.mq.producer.models.To;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import java.util.*;
import static java.lang.Thread.sleep;

        if (null == producer) {
            Boolean isStart = checkStart.get(pid);
            if (null != isStart && !isStart) {
                List<PendingMsg> messages = pendding.get(pid);
                if (null == messages) {
                    messages = new ArrayList<>();
                }
                messages.add(new PendingMsg(address, message, deliveryOption, sendCallback));
                pendding.put(pid,messages);
                return;
            } else {
                throw new RuntimeException(String.format("发送失败, 无效的pid: %s, address: %s", messageBuild.getPid(),address.name()));
            }
        }
        if (!producer.isStarted()) {
            producer.start();
        }
        if (null != sendCallback) {
            producer.sendAsync(messageBuild.getMessage(), sendCallback);
        } else {
            producer.sendOneway(messageBuild.getMessage());
        }
    }

    @Override
    public SendResult orderSend(final Enum address, final Object message, final String shardingKey) {
        return orderSend(address, message, shardingKey, null);
    }

    @Override
    public SendResult orderSend(final Enum address, final Object message, final String shardingKey, final DeliveryOption deliveryOption) {