Search in sources :

Example 6 with RemotingTimeoutException

use of org.apache.rocketmq.remoting.exception.RemotingTimeoutException in project rocketmq by apache.

the class MQClientAPIImplTest method testSendMessageAsync_WithException.

@Test
public void testSendMessageAsync_WithException() throws RemotingException, InterruptedException, MQBrokerException {
    doThrow(new RemotingTimeoutException("Remoting Exception in Test")).when(remotingClient).invokeAsync(anyString(), any(RemotingCommand.class), anyLong(), any(InvokeCallback.class));
    try {
        mqClientAPI.sendMessage(brokerAddr, brokerName, msg, new SendMessageRequestHeader(), 3 * 1000, CommunicationMode.ASYNC, new SendMessageContext(), defaultMQProducerImpl);
        failBecauseExceptionWasNotThrown(RemotingException.class);
    } catch (RemotingException e) {
        assertThat(e).hasMessage("Remoting Exception in Test");
    }
    doThrow(new InterruptedException("Interrupted Exception in Test")).when(remotingClient).invokeAsync(anyString(), any(RemotingCommand.class), anyLong(), any(InvokeCallback.class));
    try {
        mqClientAPI.sendMessage(brokerAddr, brokerName, msg, new SendMessageRequestHeader(), 3 * 1000, CommunicationMode.ASYNC, new SendMessageContext(), defaultMQProducerImpl);
        failBecauseExceptionWasNotThrown(InterruptedException.class);
    } catch (InterruptedException e) {
        assertThat(e).hasMessage("Interrupted Exception in Test");
    }
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) InvokeCallback(org.apache.rocketmq.remoting.InvokeCallback) SendMessageRequestHeader(org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) SendMessageContext(org.apache.rocketmq.client.hook.SendMessageContext) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) Test(org.junit.Test)

Example 7 with RemotingTimeoutException

use of org.apache.rocketmq.remoting.exception.RemotingTimeoutException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ClusterListSubCommand method printClusterBaseInfo.

private void printClusterBaseInfo(final DefaultMQAdminExt defaultMQAdminExt) throws RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException, InterruptedException, MQBrokerException {
    ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo();
    System.out.printf("%-16s  %-22s  %-4s  %-22s %-16s %19s %19s %10s %5s %6s%n", "#Cluster Name", "#Broker Name", "#BID", "#Addr", "#Version", "#InTPS(LOAD)", "#OutTPS(LOAD)", "#PCWait(ms)", "#Hour", "#SPACE");
    Iterator<Map.Entry<String, Set<String>>> itCluster = clusterInfoSerializeWrapper.getClusterAddrTable().entrySet().iterator();
    while (itCluster.hasNext()) {
        Map.Entry<String, Set<String>> next = itCluster.next();
        String clusterName = next.getKey();
        TreeSet<String> brokerNameSet = new TreeSet<String>();
        brokerNameSet.addAll(next.getValue());
        for (String brokerName : brokerNameSet) {
            BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
            if (brokerData != null) {
                Iterator<Map.Entry<Long, String>> itAddr = brokerData.getBrokerAddrs().entrySet().iterator();
                while (itAddr.hasNext()) {
                    Map.Entry<Long, String> next1 = itAddr.next();
                    double in = 0;
                    double out = 0;
                    String version = "";
                    String sendThreadPoolQueueSize = "";
                    String pullThreadPoolQueueSize = "";
                    String sendThreadPoolQueueHeadWaitTimeMills = "";
                    String pullThreadPoolQueueHeadWaitTimeMills = "";
                    String pageCacheLockTimeMills = "";
                    String earliestMessageTimeStamp = "";
                    String commitLogDiskRatio = "";
                    try {
                        KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(next1.getValue());
                        String putTps = kvTable.getTable().get("putTps");
                        String getTransferedTps = kvTable.getTable().get("getTransferedTps");
                        sendThreadPoolQueueSize = kvTable.getTable().get("sendThreadPoolQueueSize");
                        pullThreadPoolQueueSize = kvTable.getTable().get("pullThreadPoolQueueSize");
                        sendThreadPoolQueueSize = kvTable.getTable().get("sendThreadPoolQueueSize");
                        pullThreadPoolQueueSize = kvTable.getTable().get("pullThreadPoolQueueSize");
                        sendThreadPoolQueueHeadWaitTimeMills = kvTable.getTable().get("sendThreadPoolQueueHeadWaitTimeMills");
                        pullThreadPoolQueueHeadWaitTimeMills = kvTable.getTable().get("pullThreadPoolQueueHeadWaitTimeMills");
                        pageCacheLockTimeMills = kvTable.getTable().get("pageCacheLockTimeMills");
                        earliestMessageTimeStamp = kvTable.getTable().get("earliestMessageTimeStamp");
                        commitLogDiskRatio = kvTable.getTable().get("commitLogDiskRatio");
                        version = kvTable.getTable().get("brokerVersionDesc");
                        {
                            String[] tpss = putTps.split(" ");
                            if (tpss.length > 0) {
                                in = Double.parseDouble(tpss[0]);
                            }
                        }
                        {
                            String[] tpss = getTransferedTps.split(" ");
                            if (tpss.length > 0) {
                                out = Double.parseDouble(tpss[0]);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    double hour = 0.0;
                    double space = 0.0;
                    if (earliestMessageTimeStamp != null && earliestMessageTimeStamp.length() > 0) {
                        long mills = System.currentTimeMillis() - Long.valueOf(earliestMessageTimeStamp);
                        hour = mills / 1000.0 / 60.0 / 60.0;
                    }
                    if (commitLogDiskRatio != null && commitLogDiskRatio.length() > 0) {
                        space = Double.valueOf(commitLogDiskRatio);
                    }
                    System.out.printf("%-16s  %-22s  %-4s  %-22s %-16s %19s %19s %10s %5s %6s%n", clusterName, brokerName, next1.getKey(), next1.getValue(), version, String.format("%9.2f(%s,%sms)", in, sendThreadPoolQueueSize, sendThreadPoolQueueHeadWaitTimeMills), String.format("%9.2f(%s,%sms)", out, pullThreadPoolQueueSize, pullThreadPoolQueueHeadWaitTimeMills), pageCacheLockTimeMills, String.format("%2.2f", hour), String.format("%.4f", space));
                }
            }
        }
        if (itCluster.hasNext()) {
            System.out.printf("");
        }
    }
}
Also used : KVTable(org.apache.rocketmq.common.protocol.body.KVTable) Set(java.util.Set) TreeSet(java.util.TreeSet) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingConnectException(org.apache.rocketmq.remoting.exception.RemotingConnectException) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) TreeSet(java.util.TreeSet) Map(java.util.Map)

Example 8 with RemotingTimeoutException

use of org.apache.rocketmq.remoting.exception.RemotingTimeoutException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ClusterListSubCommand method printClusterMoreStats.

private void printClusterMoreStats(final DefaultMQAdminExt defaultMQAdminExt) throws RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException, InterruptedException, MQBrokerException {
    ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo();
    System.out.printf("%-16s  %-32s %14s %14s %14s %14s%n", "#Cluster Name", "#Broker Name", "#InTotalYest", "#OutTotalYest", "#InTotalToday", "#OutTotalToday");
    Iterator<Map.Entry<String, Set<String>>> itCluster = clusterInfoSerializeWrapper.getClusterAddrTable().entrySet().iterator();
    while (itCluster.hasNext()) {
        Map.Entry<String, Set<String>> next = itCluster.next();
        String clusterName = next.getKey();
        TreeSet<String> brokerNameSet = new TreeSet<String>();
        brokerNameSet.addAll(next.getValue());
        for (String brokerName : brokerNameSet) {
            BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
            if (brokerData != null) {
                Iterator<Map.Entry<Long, String>> itAddr = brokerData.getBrokerAddrs().entrySet().iterator();
                while (itAddr.hasNext()) {
                    Map.Entry<Long, String> next1 = itAddr.next();
                    long inTotalYest = 0;
                    long outTotalYest = 0;
                    long inTotalToday = 0;
                    long outTotalToday = 0;
                    try {
                        KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(next1.getValue());
                        String msgPutTotalYesterdayMorning = kvTable.getTable().get("msgPutTotalYesterdayMorning");
                        String msgPutTotalTodayMorning = kvTable.getTable().get("msgPutTotalTodayMorning");
                        String msgPutTotalTodayNow = kvTable.getTable().get("msgPutTotalTodayNow");
                        String msgGetTotalYesterdayMorning = kvTable.getTable().get("msgGetTotalYesterdayMorning");
                        String msgGetTotalTodayMorning = kvTable.getTable().get("msgGetTotalTodayMorning");
                        String msgGetTotalTodayNow = kvTable.getTable().get("msgGetTotalTodayNow");
                        inTotalYest = Long.parseLong(msgPutTotalTodayMorning) - Long.parseLong(msgPutTotalYesterdayMorning);
                        outTotalYest = Long.parseLong(msgGetTotalTodayMorning) - Long.parseLong(msgGetTotalYesterdayMorning);
                        inTotalToday = Long.parseLong(msgPutTotalTodayNow) - Long.parseLong(msgPutTotalTodayMorning);
                        outTotalToday = Long.parseLong(msgGetTotalTodayNow) - Long.parseLong(msgGetTotalTodayMorning);
                    } catch (Exception e) {
                    }
                    System.out.printf("%-16s  %-32s %14d %14d %14d %14d%n", clusterName, brokerName, inTotalYest, outTotalYest, inTotalToday, outTotalToday);
                }
            }
        }
        if (itCluster.hasNext()) {
            System.out.printf("");
        }
    }
}
Also used : KVTable(org.apache.rocketmq.common.protocol.body.KVTable) Set(java.util.Set) TreeSet(java.util.TreeSet) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingConnectException(org.apache.rocketmq.remoting.exception.RemotingConnectException) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) TreeSet(java.util.TreeSet) Map(java.util.Map)

Example 9 with RemotingTimeoutException

use of org.apache.rocketmq.remoting.exception.RemotingTimeoutException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class RemotingHelper method invokeSync.

/**
 * 短连接调用
 */
public static RemotingCommand invokeSync(final String addr, final RemotingCommand request, final long timeoutMillis) throws InterruptedException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException {
    long beginTime = System.currentTimeMillis();
    SocketAddress socketAddress = RemotingUtil.string2SocketAddress(addr);
    SocketChannel socketChannel = RemotingUtil.connect(socketAddress);
    if (socketChannel != null) {
        boolean sendRequestOK = false;
        try {
            // 使用阻塞模式
            socketChannel.configureBlocking(true);
            // bugfix  http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4614802
            socketChannel.socket().setSoTimeout((int) timeoutMillis);
            // 发送数据
            ByteBuffer byteBufferRequest = request.encode();
            while (byteBufferRequest.hasRemaining()) {
                int length = socketChannel.write(byteBufferRequest);
                if (length > 0) {
                    if (byteBufferRequest.hasRemaining()) {
                        if ((System.currentTimeMillis() - beginTime) > timeoutMillis) {
                            // 发送请求超时
                            throw new RemotingSendRequestException(addr);
                        }
                    }
                } else {
                    throw new RemotingSendRequestException(addr);
                }
                // 比较土
                Thread.sleep(1);
            }
            sendRequestOK = true;
            // 接收应答 SIZE
            ByteBuffer byteBufferSize = ByteBuffer.allocate(4);
            while (byteBufferSize.hasRemaining()) {
                int length = socketChannel.read(byteBufferSize);
                if (length > 0) {
                    if (byteBufferSize.hasRemaining()) {
                        if ((System.currentTimeMillis() - beginTime) > timeoutMillis) {
                            // 接收应答超时
                            throw new RemotingTimeoutException(addr, timeoutMillis);
                        }
                    }
                } else {
                    throw new RemotingTimeoutException(addr, timeoutMillis);
                }
                // 比较土
                Thread.sleep(1);
            }
            // 接收应答 BODY
            int size = byteBufferSize.getInt(0);
            ByteBuffer byteBufferBody = ByteBuffer.allocate(size);
            while (byteBufferBody.hasRemaining()) {
                int length = socketChannel.read(byteBufferBody);
                if (length > 0) {
                    if (byteBufferBody.hasRemaining()) {
                        if ((System.currentTimeMillis() - beginTime) > timeoutMillis) {
                            // 接收应答超时
                            throw new RemotingTimeoutException(addr, timeoutMillis);
                        }
                    }
                } else {
                    throw new RemotingTimeoutException(addr, timeoutMillis);
                }
                // 比较土
                Thread.sleep(1);
            }
            // 对应答数据解码
            byteBufferBody.flip();
            return RemotingCommand.decode(byteBufferBody);
        } catch (IOException e) {
            e.printStackTrace();
            if (sendRequestOK) {
                throw new RemotingTimeoutException(addr, timeoutMillis);
            } else {
                throw new RemotingSendRequestException(addr);
            }
        } finally {
            try {
                socketChannel.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } else {
        throw new RemotingConnectException(addr);
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) RemotingConnectException(org.apache.rocketmq.remoting.exception.RemotingConnectException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) IOException(java.io.IOException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ByteBuffer(java.nio.ByteBuffer)

Example 10 with RemotingTimeoutException

use of org.apache.rocketmq.remoting.exception.RemotingTimeoutException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class NettyRemotingAbstract method invokeOnewayImpl.

public void invokeOnewayImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis) throws InterruptedException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException {
    request.markOnewayRPC();
    boolean acquired = this.semaphoreOneway.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS);
    if (acquired) {
        final SemaphoreReleaseOnlyOnce once = new SemaphoreReleaseOnlyOnce(this.semaphoreOneway);
        try {
            channel.writeAndFlush(request).addListener(new ChannelFutureListener() {

                @Override
                public void operationComplete(ChannelFuture f) throws Exception {
                    once.release();
                    if (!f.isSuccess()) {
                        PLOG.warn("send a request command to channel <" + channel.remoteAddress() + "> failed.");
                    }
                }
            });
        } catch (Exception e) {
            once.release();
            PLOG.warn("write send a request command to channel <" + channel.remoteAddress() + "> failed.");
            throw new RemotingSendRequestException(RemotingHelper.parseChannelRemoteAddr(channel), e);
        }
    } else {
        if (timeoutMillis <= 0) {
            throw new RemotingTooMuchRequestException("invokeOnewayImpl invoke too fast");
        } else {
            String info = String.format(// 
            "invokeOnewayImpl tryAcquire semaphore timeout, %dms, waiting thread nums: %d semaphoreAsyncValue: %d", // 
            timeoutMillis, // 
            this.semaphoreOneway.getQueueLength(), // 
            this.semaphoreOneway.availablePermits());
            PLOG.warn(info);
            throw new RemotingTimeoutException(info);
        }
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) ChannelFutureListener(io.netty.channel.ChannelFutureListener) RemotingTooMuchRequestException(org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) SemaphoreReleaseOnlyOnce(org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce) RemotingTooMuchRequestException(org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException)

Aggregations

RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)20 RemotingSendRequestException (org.apache.rocketmq.remoting.exception.RemotingSendRequestException)12 RemotingConnectException (org.apache.rocketmq.remoting.exception.RemotingConnectException)8 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)8 ChannelFuture (io.netty.channel.ChannelFuture)6 ChannelFutureListener (io.netty.channel.ChannelFutureListener)6 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)6 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)6 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)6 RemotingTooMuchRequestException (org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException)6 IOException (java.io.IOException)4 SocketAddress (java.net.SocketAddress)4 UnknownHostException (java.net.UnknownHostException)4 Map (java.util.Map)4 Set (java.util.Set)4 TreeSet (java.util.TreeSet)4 SendMessageContext (org.apache.rocketmq.client.hook.SendMessageContext)4 ClusterInfo (org.apache.rocketmq.common.protocol.body.ClusterInfo)4 KVTable (org.apache.rocketmq.common.protocol.body.KVTable)4 SendMessageRequestHeader (org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader)4