org.apache.rocketmq.common.MQVersion Java Examples

The following examples show how to use org.apache.rocketmq.common.MQVersion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MonitorService.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException,
    MQBrokerException, RemotingException, MQClientException {
    ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
    TreeMap<String, ConsumerRunningInfo> infoMap = new TreeMap<String, ConsumerRunningInfo>();
    for (Connection c : cc.getConnectionSet()) {
        String clientId = c.getClientId();

        if (c.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
            continue;
        }

        try {
            ConsumerRunningInfo info =
                defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false);
            infoMap.put(clientId, info);
        } catch (Exception e) {
        }
    }

    if (!infoMap.isEmpty()) {
        this.monitorListener.reportConsumerRunningInfo(infoMap);
    }
}
 
Example #2
Source File: MonitorService.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException,
    MQBrokerException, RemotingException, MQClientException {
    ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
    TreeMap<String, ConsumerRunningInfo> infoMap = new TreeMap<String, ConsumerRunningInfo>();
    for (Connection c : cc.getConnectionSet()) {
        String clientId = c.getClientId();

        if (c.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
            continue;
        }

        try {
            ConsumerRunningInfo info =
                defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false);
            infoMap.put(clientId, info);
        } catch (Exception e) {
        }
    }

    if (!infoMap.isEmpty()) {
        this.monitorListener.reportConsumerRunningInfo(infoMap);
    }
}
 
Example #3
Source File: FiltersrvControllerTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
        // 设置版本号
        System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
        //
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(30911);
        //
        final FiltersrvConfig filtersrvConfig = new FiltersrvConfig();
        filtersrvConfig.setNamesrvAddr("127.0.0.1:9876");

        // filter 启动
        FiltersrvController filtersrvController = new FiltersrvController(
                filtersrvConfig,
                nettyServerConfig
        );
        boolean initResult = filtersrvController.initialize();
        System.out.println("initResult:" + initResult);
//        filtersrvController
        filtersrvController.start();
        Thread.sleep(DateUtils.MILLIS_PER_DAY);
    }
 
Example #4
Source File: FiltersrvControllerSlaveTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
        // 设置版本号
        System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
        //
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(30912);
        //
        final FiltersrvConfig filtersrvConfig = new FiltersrvConfig();
        filtersrvConfig.setNamesrvAddr("127.0.0.1:9876");
        filtersrvConfig.setConnectWhichBroker("127.0.0.1:20911");

        // filter 启动
        FiltersrvController filtersrvController = new FiltersrvController(
                filtersrvConfig,
                nettyServerConfig
        );
        boolean initResult = filtersrvController.initialize();
        System.out.println("initResult:" + initResult);
//        filtersrvController
        filtersrvController.start();
        Thread.sleep(DateUtils.MILLIS_PER_DAY);
    }
 
Example #5
Source File: MonitorService.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException,
    MQBrokerException, RemotingException, MQClientException {
    ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
    TreeMap<String, ConsumerRunningInfo> infoMap = new TreeMap<String, ConsumerRunningInfo>();
    for (Connection c : cc.getConnectionSet()) {
        String clientId = c.getClientId();

        if (c.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
            continue;
        }

        try {
            ConsumerRunningInfo info =
                defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false);
            infoMap.put(clientId, info);
        } catch (Exception e) {
        }
    }

    if (!infoMap.isEmpty()) {
        this.monitorListener.reportConsumerRunningInfo(infoMap);
    }
}
 
Example #6
Source File: MonitorService.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException,
    MQBrokerException, RemotingException, MQClientException {
    ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
    TreeMap<String, ConsumerRunningInfo> infoMap = new TreeMap<String, ConsumerRunningInfo>();
    for (Connection c : cc.getConnectionSet()) {
        String clientId = c.getClientId();

        if (c.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
            continue;
        }

        try {
            ConsumerRunningInfo info =
                defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false);
            infoMap.put(clientId, info);
        } catch (Exception e) {
        }
    }

    if (!infoMap.isEmpty()) {
        this.monitorListener.reportConsumerRunningInfo(infoMap);
    }
}
 
Example #7
Source File: MonitorService.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException,
    MQBrokerException, RemotingException, MQClientException {
    ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
    TreeMap<String, ConsumerRunningInfo> infoMap = new TreeMap<String, ConsumerRunningInfo>();
    for (Connection c : cc.getConnectionSet()) {
        String clientId = c.getClientId();

        if (c.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
            continue;
        }

        try {
            ConsumerRunningInfo info =
                defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false);
            infoMap.put(clientId, info);
        } catch (Exception e) {
        }
    }

    if (!infoMap.isEmpty()) {
        this.monitorListener.reportConsumerRunningInfo(infoMap);
    }
}
 
Example #8
Source File: MonitorService.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException,
    MQBrokerException, RemotingException, MQClientException {
    ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
    TreeMap<String, ConsumerRunningInfo> infoMap = new TreeMap<String, ConsumerRunningInfo>();
    for (Connection c : cc.getConnectionSet()) {
        String clientId = c.getClientId();

        if (c.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
            continue;
        }

        try {
            ConsumerRunningInfo info =
                defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false);
            infoMap.put(clientId, info);
        } catch (Exception e) {
        }
    }

    if (!infoMap.isEmpty()) {
        this.monitorListener.reportConsumerRunningInfo(infoMap);
    }
}
 
Example #9
Source File: MQClientInstance.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 实例化mqclientinstance
 * @param clientConfig 客户端config
 * @param instanceIndex 实例index
 * @param clientId 客户端id
 * @param rpcHook rpc勾子
 */
public MQClientInstance(ClientConfig clientConfig, int instanceIndex, String clientId, RPCHook rpcHook) {
    this.clientConfig = clientConfig;
    this.instanceIndex = instanceIndex;
    this.nettyClientConfig = new NettyClientConfig();
    //设置了一下setClientCallbackExecutorThreads
    this.nettyClientConfig.setClientCallbackExecutorThreads(clientConfig.getClientCallbackExecutorThreads());
    this.nettyClientConfig.setUseTLS(clientConfig.isUseTLS());
    this.clientRemotingProcessor = new ClientRemotingProcessor(this);

    this.mQClientAPIImpl = new MQClientAPIImpl(this.nettyClientConfig, this.clientRemotingProcessor, rpcHook, clientConfig);

    if (this.clientConfig.getNamesrvAddr() != null) {
        //设置NameServer的地址
        this.mQClientAPIImpl.updateNameServerAddressList(this.clientConfig.getNamesrvAddr());
        log.info("user specified name server address: {}", this.clientConfig.getNamesrvAddr());
    }

    this.clientId = clientId;
    this.mQAdminImpl = new MQAdminImpl(this);
    this.pullMessageService = new PullMessageService(this);
    this.rebalanceService = new RebalanceService(this);
    //defaultMqProducer为CLIENT_INNER_PRODUCER_GROUP
    this.defaultMQProducer = new DefaultMQProducer(MixAll.CLIENT_INNER_PRODUCER_GROUP);
    this.defaultMQProducer.resetClientConfig(clientConfig);

    this.consumerStatsManager = new ConsumerStatsManager(this.scheduledExecutorService);

    log.info("Created a new client Instance, InstanceIndex:{}, ClientID:{}, ClientConfig:{}, ClientVersion:{}, SerializerType:{}",
        this.instanceIndex,
        this.clientId,
        this.clientConfig,
        MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION), RemotingCommand.getSerializeTypeConfigInThisServer());
}
 
Example #10
Source File: HttpTinyClient.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
static private void setHeaders(HttpURLConnection conn, List<String> headers, String encoding) {
    if (null != headers) {
        for (Iterator<String> iter = headers.iterator(); iter.hasNext(); ) {
            conn.addRequestProperty(iter.next(), iter.next());
        }
    }
    conn.addRequestProperty("Client-Version", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION));
    conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);

    String ts = String.valueOf(System.currentTimeMillis());
    conn.addRequestProperty("Metaq-Client-RequestTS", ts);
}
 
Example #11
Source File: HttpTinyClient.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
static private void setHeaders(HttpURLConnection conn, List<String> headers, String encoding) {
    if (null != headers) {
        for (Iterator<String> iter = headers.iterator(); iter.hasNext(); ) {
            conn.addRequestProperty(iter.next(), iter.next());
        }
    }
    conn.addRequestProperty("Client-Version", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION));
    conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);

    String ts = String.valueOf(System.currentTimeMillis());
    conn.addRequestProperty("Metaq-Client-RequestTS", ts);
}
 
Example #12
Source File: BrokerStartupTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
// 设置版本号
        System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
        // NettyServerConfig 配置
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(10911);
        // BrokerConfig 配置
        final BrokerConfig brokerConfig = new BrokerConfig();
        brokerConfig.setBrokerName("broker-a");
        brokerConfig.setNamesrvAddr("127.0.0.1:9876");
        // MessageStoreConfig 配置
        final MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
        messageStoreConfig.setDeleteWhen("04");
        messageStoreConfig.setFileReservedTime(48);
        messageStoreConfig.setFlushDiskType(FlushDiskType.ASYNC_FLUSH);
        messageStoreConfig.setDuplicationEnable(false);

//        BrokerPathConfigHelper.setBrokerConfigPath("/Users/yunai/百度云同步盘/开发/Javascript/Story/incubator-rocketmq/conf/broker.conf");
        // 创建 BrokerController 对象,并启动
        BrokerController brokerController = new BrokerController(//
                brokerConfig, //
                nettyServerConfig, //
                new NettyClientConfig(), //
                messageStoreConfig);
        brokerController.initialize();
        brokerController.start();
        // 睡觉,就不起来
        System.out.println("你猜");
        Thread.sleep(DateUtils.MILLIS_PER_DAY);
    }
 
Example #13
Source File: ProducerConnectionSubCommand.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();

        String group = commandLine.getOptionValue('g').trim();
        String topic = commandLine.getOptionValue('t').trim();

        ProducerConnection pc = defaultMQAdminExt.examineProducerConnectionInfo(group, topic);

        int i = 1;
        for (Connection conn : pc.getConnectionSet()) {
            System.out.printf("%04d  %-32s %-22s %-8s %s%n",
                i++,
                conn.getClientId(),
                conn.getClientAddr(),
                conn.getLanguage(),
                MQVersion.getVersionDesc(conn.getVersion())
            );
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #14
Source File: ProducerConnectionSubCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();

        String group = commandLine.getOptionValue('g').trim();
        String topic = commandLine.getOptionValue('t').trim();

        ProducerConnection pc = defaultMQAdminExt.examineProducerConnectionInfo(group, topic);

        int i = 1;
        for (Connection conn : pc.getConnectionSet()) {
            System.out.printf("%04d  %-32s %-22s %-8s %s%n",
                i++,
                conn.getClientId(),
                conn.getClientAddr(),
                conn.getLanguage(),
                MQVersion.getVersionDesc(conn.getVersion())
            );
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #15
Source File: ProducerConnectionSubCommand.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();

        String group = commandLine.getOptionValue('g').trim();
        String topic = commandLine.getOptionValue('t').trim();

        ProducerConnection pc = defaultMQAdminExt.examineProducerConnectionInfo(group, topic);

        int i = 1;
        for (Connection conn : pc.getConnectionSet()) {
            System.out.printf("%04d  %-32s %-22s %-8s %s%n",
                i++,
                conn.getClientId(),
                conn.getClientAddr(),
                conn.getLanguage(),
                MQVersion.getVersionDesc(conn.getVersion())
            );
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #16
Source File: MQClientInstance.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public MQClientInstance(ClientConfig clientConfig, int instanceIndex, String clientId, RPCHook rpcHook) {
    this.clientConfig = clientConfig;
    this.instanceIndex = instanceIndex;
    this.nettyClientConfig = new NettyClientConfig();
    this.nettyClientConfig.setClientCallbackExecutorThreads(clientConfig.getClientCallbackExecutorThreads());
    this.nettyClientConfig.setUseTLS(clientConfig.isUseTLS());
    this.clientRemotingProcessor = new ClientRemotingProcessor(this);
    this.mQClientAPIImpl = new MQClientAPIImpl(this.nettyClientConfig, this.clientRemotingProcessor, rpcHook, clientConfig);

    if (this.clientConfig.getNamesrvAddr() != null) {
        this.mQClientAPIImpl.updateNameServerAddressList(this.clientConfig.getNamesrvAddr());
        log.info("user specified name server address: {}", this.clientConfig.getNamesrvAddr());
    }

    this.clientId = clientId;

    this.mQAdminImpl = new MQAdminImpl(this);

    this.pullMessageService = new PullMessageService(this);

    this.rebalanceService = new RebalanceService(this);

    this.defaultMQProducer = new DefaultMQProducer(MixAll.CLIENT_INNER_PRODUCER_GROUP);
    this.defaultMQProducer.resetClientConfig(clientConfig);

    this.consumerStatsManager = new ConsumerStatsManager(this.scheduledExecutorService);

    log.info("created a new client Instance, FactoryIndex: {} ClinetID: {} {} {}, serializeType={}",
        this.instanceIndex,
        this.clientId,
        this.clientConfig,
        MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION), RemotingCommand.getSerializeTypeConfigInThisServer());
}
 
Example #17
Source File: ProducerConnectionSubCommand.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();

        String group = commandLine.getOptionValue('g').trim();
        String topic = commandLine.getOptionValue('t').trim();

        ProducerConnection pc = defaultMQAdminExt.examineProducerConnectionInfo(group, topic);

        int i = 1;
        for (Connection conn : pc.getConnectionSet()) {
            System.out.printf("%04d  %-32s %-22s %-8s %s%n",
                i++,
                conn.getClientId(),
                conn.getClientAddr(),
                conn.getLanguage(),
                MQVersion.getVersionDesc(conn.getVersion())
            );
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #18
Source File: HttpTinyClient.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
static private void setHeaders(HttpURLConnection conn, List<String> headers, String encoding) {
    if (null != headers) {
        for (Iterator<String> iter = headers.iterator(); iter.hasNext(); ) {
            conn.addRequestProperty(iter.next(), iter.next());
        }
    }
    conn.addRequestProperty("Client-Version", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION));
    conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);

    String ts = String.valueOf(System.currentTimeMillis());
    conn.addRequestProperty("Metaq-Client-RequestTS", ts);
}
 
Example #19
Source File: HttpTinyClient.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 设置请求头
 * @param conn conn
 * @param headers headers
 * @param encoding 编码
 */
static private void setHeaders(HttpURLConnection conn, List<String> headers, String encoding) {
    if (null != headers) {
        for (Iterator<String> iter = headers.iterator(); iter.hasNext(); ) {
            conn.addRequestProperty(iter.next(), iter.next());
        }
    }
    conn.addRequestProperty("Client-Version", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION));
    conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);

    String ts = String.valueOf(System.currentTimeMillis());
    conn.addRequestProperty("Metaq-Client-RequestTS", ts);
}
 
Example #20
Source File: BrokerControllerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
/**
     * broker 启动
     */
    @Test
    public void testBrokerRestart() throws Exception {
        // 设置版本号
        System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
        //
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(10911);
        //
        final BrokerConfig brokerConfig = new BrokerConfig();
        brokerConfig.setBrokerName("broker-a");
        brokerConfig.setNamesrvAddr("127.0.0.1:9876");
        //
        final MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
        messageStoreConfig.setDeleteWhen("04");
        messageStoreConfig.setFileReservedTime(48);
        messageStoreConfig.setFlushDiskType(FlushDiskType.ASYNC_FLUSH);

        messageStoreConfig.setDuplicationEnable(false);

//        BrokerPathConfigHelper.setBrokerConfigPath("/Users/yunai/百度云同步盘/开发/Javascript/Story/incubator-rocketmq/conf/broker.conf");
        // broker 启动
        BrokerController brokerController = new BrokerController(//
                brokerConfig, //
                nettyServerConfig, //
                new NettyClientConfig(), //
                messageStoreConfig);
        brokerController.initialize();
        brokerController.start();
//        brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod()
        Thread.sleep(DateUtils.MILLIS_PER_DAY);
    }
 
Example #21
Source File: BrokerControllerSlaveTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
/**
     * broker 启动
     */
    @Test
    public void testBrokerRestart() throws Exception {
        System.setProperty("user.home", System.getProperty("user.home") + File.separator + "broker" + File.separator + "slave");

        // 设置版本号
        System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
        //
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(20911);
        //
        final BrokerConfig brokerConfig = new BrokerConfig();
        brokerConfig.setBrokerName("broker-a");
        brokerConfig.setBrokerId(1L); // 1
        brokerConfig.setNamesrvAddr("127.0.0.1:9876");

        //
        final MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
        messageStoreConfig.setDeleteWhen("04");
        messageStoreConfig.setFileReservedTime(48);
        messageStoreConfig.setFlushDiskType(FlushDiskType.ASYNC_FLUSH);
        messageStoreConfig.setBrokerRole(BrokerRole.SLAVE);

        messageStoreConfig.setDuplicationEnable(false);

        messageStoreConfig.setHaListenPort(nettyServerConfig.getListenPort() + 1);

//        BrokerPathConfigHelper.setBrokerConfigPath("/Users/yunai/百度云同步盘/开发/Javascript/Story/incubator-rocketmq/conf/broker.conf");
        // broker 启动
        BrokerController brokerController = new BrokerController(//
                brokerConfig, //
                nettyServerConfig, //
                new NettyClientConfig(), //
                messageStoreConfig);
        brokerController.initialize();
        brokerController.start();
//        brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod()
        Thread.sleep(DateUtils.MILLIS_PER_DAY);
    }
 
Example #22
Source File: HttpTinyClient.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
static private void setHeaders(HttpURLConnection conn, List<String> headers, String encoding) {
    if (null != headers) {
        for (Iterator<String> iter = headers.iterator(); iter.hasNext(); ) {
            conn.addRequestProperty(iter.next(), iter.next());
        }
    }
    conn.addRequestProperty("Client-Version", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION));
    conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);

    String ts = String.valueOf(System.currentTimeMillis());
    conn.addRequestProperty("Metaq-Client-RequestTS", ts);
}
 
Example #23
Source File: HttpTinyClient.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
static private void setHeaders(HttpURLConnection conn, List<String> headers, String encoding) {
    if (null != headers) {
        for (Iterator<String> iter = headers.iterator(); iter.hasNext(); ) {
            conn.addRequestProperty(iter.next(), iter.next());
        }
    }
    conn.addRequestProperty("Client-Version", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION));
    conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);

    String ts = String.valueOf(System.currentTimeMillis());
    conn.addRequestProperty("Metaq-Client-RequestTS", ts);
}
 
Example #24
Source File: HttpTinyClient.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
static private void setHeaders(HttpURLConnection conn, List<String> headers, String encoding) {
    if (null != headers) {
        for (Iterator<String> iter = headers.iterator(); iter.hasNext(); ) {
            conn.addRequestProperty(iter.next(), iter.next());
        }
    }
    conn.addRequestProperty("Client-Version", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION));
    conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);

    String ts = String.valueOf(System.currentTimeMillis());
    conn.addRequestProperty("Metaq-Client-RequestTS", ts);
}
 
Example #25
Source File: MQClientInstance.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public MQClientInstance(ClientConfig clientConfig, int instanceIndex, String clientId, RPCHook rpcHook) {
    this.clientConfig = clientConfig;
    this.instanceIndex = instanceIndex;
    this.nettyClientConfig = new NettyClientConfig();
    this.nettyClientConfig.setClientCallbackExecutorThreads(clientConfig.getClientCallbackExecutorThreads());
    this.clientRemotingProcessor = new ClientRemotingProcessor(this);
    this.mQClientAPIImpl = new MQClientAPIImpl(this.nettyClientConfig, this.clientRemotingProcessor, rpcHook, clientConfig);

    if (this.clientConfig.getNamesrvAddr() != null) {
        this.mQClientAPIImpl.updateNameServerAddressList(this.clientConfig.getNamesrvAddr());
        log.info("user specified name server address: {}", this.clientConfig.getNamesrvAddr());
    }

    this.clientId = clientId;

    this.mQAdminImpl = new MQAdminImpl(this);

    this.pullMessageService = new PullMessageService(this);

    this.rebalanceService = new RebalanceService(this);

    this.defaultMQProducer = new DefaultMQProducer(MixAll.CLIENT_INNER_PRODUCER_GROUP);
    this.defaultMQProducer.resetClientConfig(clientConfig);

    this.consumerStatsManager = new ConsumerStatsManager(this.scheduledExecutorService);

    log.info("created a new client Instance, FactoryIndex: {} ClinetID: {} {} {}, serializeType={}", //
        this.instanceIndex, //
        this.clientId, //
        this.clientConfig, //
        MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION), RemotingCommand.getSerializeTypeConfigInThisServer());
}
 
Example #26
Source File: ProducerConnectionSubCommand.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();

        String group = commandLine.getOptionValue('g').trim();
        String topic = commandLine.getOptionValue('t').trim();

        ProducerConnection pc = defaultMQAdminExt.examineProducerConnectionInfo(group, topic);

        int i = 1;
        for (Connection conn : pc.getConnectionSet()) {
            System.out.printf("%04d  %-32s %-22s %-8s %s%n",
                i++,
                conn.getClientId(),
                conn.getClientAddr(),
                conn.getLanguage(),
                MQVersion.getVersionDesc(conn.getVersion())
            );
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #27
Source File: ProducerConnectionSubCommand.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();

        String group = commandLine.getOptionValue('g').trim();
        String topic = commandLine.getOptionValue('t').trim();

        ProducerConnection pc = defaultMQAdminExt.examineProducerConnectionInfo(group, topic);

        int i = 1;
        for (Connection conn : pc.getConnectionSet()) {
            System.out.printf("%04d  %-32s %-22s %-8s %s%n",
                i++,
                conn.getClientId(),
                conn.getClientAddr(),
                conn.getLanguage(),
                MQVersion.getVersionDesc(conn.getVersion())
            );
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #28
Source File: HttpTinyClient.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
static private void setHeaders(HttpURLConnection conn, List<String> headers, String encoding) {
    if (null != headers) {
        for (Iterator<String> iter = headers.iterator(); iter.hasNext(); ) {
            conn.addRequestProperty(iter.next(), iter.next());
        }
    }
    conn.addRequestProperty("Client-Version", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION));
    conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);

    String ts = String.valueOf(System.currentTimeMillis());
    conn.addRequestProperty("Metaq-Client-RequestTS", ts);
}
 
Example #29
Source File: MQClientInstance.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public MQClientInstance(ClientConfig clientConfig, int instanceIndex, String clientId, RPCHook rpcHook) {
    this.clientConfig = clientConfig;
    this.instanceIndex = instanceIndex;
    this.nettyClientConfig = new NettyClientConfig();
    this.nettyClientConfig.setClientCallbackExecutorThreads(clientConfig.getClientCallbackExecutorThreads());
    this.nettyClientConfig.setUseTLS(clientConfig.isUseTLS());
    this.clientRemotingProcessor = new ClientRemotingProcessor(this);
    this.mQClientAPIImpl = new MQClientAPIImpl(this.nettyClientConfig, this.clientRemotingProcessor, rpcHook, clientConfig);

    if (this.clientConfig.getNamesrvAddr() != null) {
        this.mQClientAPIImpl.updateNameServerAddressList(this.clientConfig.getNamesrvAddr());
        log.info("user specified name server address: {}", this.clientConfig.getNamesrvAddr());
    }

    this.clientId = clientId;

    this.mQAdminImpl = new MQAdminImpl(this);

    this.pullMessageService = new PullMessageService(this);

    this.rebalanceService = new RebalanceService(this);

    this.defaultMQProducer = new DefaultMQProducer(MixAll.CLIENT_INNER_PRODUCER_GROUP);
    this.defaultMQProducer.resetClientConfig(clientConfig);

    this.consumerStatsManager = new ConsumerStatsManager(this.scheduledExecutorService);

    log.info("Created a new client Instance, InstanceIndex:{}, ClientID:{}, ClientConfig:{}, ClientVersion:{}, SerializerType:{}",
        this.instanceIndex,
        this.clientId,
        this.clientConfig,
        MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION), RemotingCommand.getSerializeTypeConfigInThisServer());
}
 
Example #30
Source File: MonitorServiceTest.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException {
    monitorConfig = new MonitorConfig();
    monitorListener = new DefaultMonitorListener();
    defaultMQPullConsumer = mock(DefaultMQPullConsumer.class);
    defaultMQPushConsumer = mock(DefaultMQPushConsumer.class);
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    monitorService = new MonitorService(monitorConfig, monitorListener, null);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);

    field = MonitorService.class.getDeclaredField("defaultMQAdminExt");
    field.setAccessible(true);
    field.set(monitorService, defaultMQAdminExt);
    field = MonitorService.class.getDeclaredField("defaultMQPullConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPullConsumer);
    field = MonitorService.class.getDeclaredField("defaultMQPushConsumer");
    field.setAccessible(true);
    field.set(monitorService, defaultMQPushConsumer);

    TopicList topicList = new TopicList();
    Set<String> topicSet = new HashSet<>();
    topicSet.add("topic_one");
    topicSet.add("topic_two");
    topicList.setTopicList(topicSet);
    when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList);

    TopicRouteData topicRouteData = new TopicRouteData();
    List<BrokerData> brokerDatas = new ArrayList<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerName("default-broker");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDatas.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDatas);
    topicRouteData.setQueueDatas(new ArrayList<QueueData>());
    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);

    ConsumeStats consumeStats = new ConsumeStats();
    consumeStats.setConsumeTps(1234);
    MessageQueue messageQueue = new MessageQueue();
    OffsetWrapper offsetWrapper = new OffsetWrapper();
    HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>();
    stats.put(messageQueue, offsetWrapper);
    consumeStats.setOffsetTable(stats);
    when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats);

    ConsumerConnection consumerConnection = new ConsumerConnection();
    consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY);
    consumerConnection.setMessageModel(MessageModel.CLUSTERING);
    HashSet<Connection> connections = new HashSet<>();
    Connection connection = new Connection();
    connection.setClientId("client_id");
    connection.setClientAddr("127.0.0.1:109111");
    connection.setLanguage(LanguageCode.JAVA);
    connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal());
    connections.add(connection);
    consumerConnection.setConnectionSet(connections);
    consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>());
    consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection);

    ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo();
    consumerRunningInfo.setJstack("test");
    consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>());
    consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>());
    consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>());
    Properties properties = new Properties();
    properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY);
    properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis());
    consumerRunningInfo.setProperties(properties);
    when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo);
}