org.apache.rocketmq.store.MessageStore Java Examples

The following examples show how to use org.apache.rocketmq.store.MessageStore. 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: MessageStoreFactory.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public final static MessageStore build(MessageStorePluginContext context, MessageStore messageStore)
    throws IOException {
    String plugin = context.getBrokerConfig().getMessageStorePlugIn();
    if (plugin != null && plugin.trim().length() != 0) {
        String[] pluginClasses = plugin.split(",");
        for (int i = pluginClasses.length - 1; i >= 0; --i) {
            String pluginClass = pluginClasses[i];
            try {
                @SuppressWarnings("unchecked")
                Class<AbstractPluginMessageStore> clazz = (Class<AbstractPluginMessageStore>) Class.forName(pluginClass);
                Constructor<AbstractPluginMessageStore> construct = clazz.getConstructor(MessageStorePluginContext.class, MessageStore.class);
                messageStore = construct.newInstance(context, messageStore);
            } catch (Throwable e) {
                throw new RuntimeException(String.format(
                    "Initialize plugin's class %s not found!", pluginClass), e);
            }
        }
    }
    return messageStore;
}
 
Example #2
Source File: MessageStoreFactory.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public final static MessageStore build(MessageStorePluginContext context, MessageStore messageStore)
    throws IOException {
    String plugin = context.getBrokerConfig().getMessageStorePlugIn();
    if (plugin != null && plugin.trim().length() != 0) {
        String[] pluginClasses = plugin.split(",");
        for (int i = pluginClasses.length - 1; i >= 0; --i) {
            String pluginClass = pluginClasses[i];
            try {
                @SuppressWarnings("unchecked")
                Class<AbstractPluginMessageStore> clazz = (Class<AbstractPluginMessageStore>) Class.forName(pluginClass);
                Constructor<AbstractPluginMessageStore> construct = clazz.getConstructor(MessageStorePluginContext.class, MessageStore.class);
                messageStore = construct.newInstance(context, messageStore);
            } catch (Throwable e) {
                throw new RuntimeException(String.format(
                    "Initialize plugin's class %s not found!", pluginClass), e);
            }
        }
    }
    return messageStore;
}
 
Example #3
Source File: MessageStoreFactory.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public final static MessageStore build(MessageStorePluginContext context, MessageStore messageStore)
    throws IOException {
    String plugin = context.getBrokerConfig().getMessageStorePlugIn();
    if (plugin != null && plugin.trim().length() != 0) {
        String[] pluginClasses = plugin.split(",");
        for (int i = pluginClasses.length - 1; i >= 0; --i) {
            String pluginClass = pluginClasses[i];
            try {
                @SuppressWarnings("unchecked")
                Class<AbstractPluginMessageStore> clazz = (Class<AbstractPluginMessageStore>) Class.forName(pluginClass);
                Constructor<AbstractPluginMessageStore> construct = clazz.getConstructor(MessageStorePluginContext.class, MessageStore.class);
                messageStore = construct.newInstance(context, messageStore);
            } catch (Throwable e) {
                throw new RuntimeException(String.format(
                    "Initialize plugin's class %s not found!", pluginClass), e);
            }
        }
    }
    return messageStore;
}
 
Example #4
Source File: MessageStoreFactory.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public final static MessageStore build(MessageStorePluginContext context, MessageStore messageStore)
    throws IOException {
    String plugin = context.getBrokerConfig().getMessageStorePlugIn();
    if (plugin != null && plugin.trim().length() != 0) {
        String[] pluginClasses = plugin.split(",");
        for (int i = pluginClasses.length - 1; i >= 0; --i) {
            String pluginClass = pluginClasses[i];
            try {
                @SuppressWarnings("unchecked")
                Class<AbstractPluginMessageStore> clazz = (Class<AbstractPluginMessageStore>) Class.forName(pluginClass);
                Constructor<AbstractPluginMessageStore> construct = clazz.getConstructor(MessageStorePluginContext.class, MessageStore.class);
                messageStore = construct.newInstance(context, messageStore);
            } catch (Throwable e) {
                throw new RuntimeException(String.format(
                    "Initialize plugin's class %s not found!", pluginClass), e);
            }
        }
    }
    return messageStore;
}
 
Example #5
Source File: MessageStoreFactory.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * reBuildMessageStore
 * @param context context
 * @param messageStore ;
 * @return ;
 * @throws IOException ;
 */
public final static MessageStore build(MessageStorePluginContext context, MessageStore messageStore)
    throws IOException {

    //其实就是包装了MessageStore,通过层层装饰。类名逗号间隔。在brokerConfig中MessageStorePlugIn配置
    String plugin = context.getBrokerConfig().getMessageStorePlugIn();
    if (plugin != null && plugin.trim().length() != 0) {
        String[] pluginClasses = plugin.split(",");
        for (int i = pluginClasses.length - 1; i >= 0; --i) {
            String pluginClass = pluginClasses[i];
            try {
                @SuppressWarnings("unchecked")
                Class<AbstractPluginMessageStore> clazz = (Class<AbstractPluginMessageStore>) Class.forName(pluginClass);
                Constructor<AbstractPluginMessageStore> construct = clazz.getConstructor(MessageStorePluginContext.class, MessageStore.class);
                messageStore = construct.newInstance(context, messageStore);
            } catch (Throwable e) {
                throw new RuntimeException(String.format(
                    "Initialize plugin's class %s not found!", pluginClass), e);
            }
        }
    }
    return messageStore;
}
 
Example #6
Source File: DeFiReplyMessageProcessorTest.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    deFiBrokerController = spy(new DeFiBrokerController(new BrokerConfig(), new NettyServerConfig(), new NettyClientConfig(), new MessageStoreConfig(), deFiBusBrokerConfig));
    channelHandlerContext = mock(ChannelHandlerContext.class);
    messageStore = mock(MessageStore.class);
    DeFiBusBroker2Client broker2Client = mock(DeFiBusBroker2Client.class);
    when(this.deFiBrokerController.getDeFiBusBroker2Client()).thenReturn(broker2Client);
    when(broker2Client.pushRRReplyMessageToClient(any(), any(), any())).thenReturn(true);
    Channel channel = mock(Channel.class);
    when(channel.isActive()).thenReturn(true);
    ClientChannelInfo channelInfo = mock(ClientChannelInfo.class);
    when(channelInfo.getChannel()).thenReturn(channel);
    DeFiProducerManager mockProducer = mock(DeFiProducerManager.class);
    when(mockProducer.getClientChannel(anyString())).thenReturn(channelInfo);
    when(this.deFiBrokerController.getProducerManager()).thenReturn(mockProducer);
    this.deFiBrokerController.setMessageStore(this.messageStore);
    when(this.messageStore.now()).thenReturn(System.currentTimeMillis());
    AppendMessageResult appendMessageResult = new AppendMessageResult(AppendMessageStatus.PUT_OK, 0, 0, "00000000000000000000000000000000", messageStore.now(), 0L, 0);
    when(this.messageStore.putMessage(any())).thenReturn(new PutMessageResult(PutMessageStatus.PUT_OK, appendMessageResult));
    when(channel.remoteAddress()).thenReturn(new InetSocketAddress(1024));
    when(channelHandlerContext.channel()).thenReturn(channel);
    deFiReplyMessageProcessor = new DeFiReplyMessageProcessor(this.deFiBrokerController);
}
 
Example #7
Source File: MessageStoreFactory.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public final static MessageStore build(MessageStorePluginContext context, MessageStore messageStore)
    throws IOException {
    String plugin = context.getBrokerConfig().getMessageStorePlugIn();
    if (plugin != null && plugin.trim().length() != 0) {
        String[] pluginClasses = plugin.split(",");
        for (int i = pluginClasses.length - 1; i >= 0; --i) {
            String pluginClass = pluginClasses[i];
            try {
                @SuppressWarnings("unchecked")
                Class<AbstractPluginMessageStore> clazz = (Class<AbstractPluginMessageStore>) Class.forName(pluginClass);
                Constructor<AbstractPluginMessageStore> construct = clazz.getConstructor(MessageStorePluginContext.class, MessageStore.class);
                messageStore = construct.newInstance(context, messageStore);
            } catch (Throwable e) {
                throw new RuntimeException(String.format(
                    "Initialize plugin's class %s not found!", pluginClass), e);
            }
        }
    }
    return messageStore;
}
 
Example #8
Source File: MessageStoreFactory.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public final static MessageStore build(MessageStorePluginContext context, MessageStore messageStore)
    throws IOException {
    String plugin = context.getBrokerConfig().getMessageStorePlugIn();
    if (plugin != null && plugin.trim().length() != 0) {
        String[] pluginClasses = plugin.split(",");
        for (int i = pluginClasses.length - 1; i >= 0; --i) {
            String pluginClass = pluginClasses[i];
            try {
                @SuppressWarnings("unchecked")
                Class<AbstractPluginMessageStore> clazz = (Class<AbstractPluginMessageStore>) Class.forName(pluginClass);
                Constructor<AbstractPluginMessageStore> construct = clazz.getConstructor(MessageStorePluginContext.class, MessageStore.class);
                messageStore = construct.newInstance(context, messageStore);
            } catch (Throwable e) {
                throw new RuntimeException(String.format(
                    "Initialize plugin's class %s not found!", pluginClass), e);
            }
        }
    }
    return messageStore;
}
 
Example #9
Source File: MessageStoreFactory.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public final static MessageStore build(MessageStorePluginContext context, MessageStore messageStore)
    throws IOException {
    String plugin = context.getBrokerConfig().getMessageStorePlugIn();
    if (plugin != null && plugin.trim().length() != 0) {
        String[] pluginClasses = plugin.split(",");
        for (int i = pluginClasses.length - 1; i >= 0; --i) {
            String pluginClass = pluginClasses[i];
            try {
                @SuppressWarnings("unchecked")
                Class<AbstractPluginMessageStore> clazz = (Class<AbstractPluginMessageStore>) Class.forName(pluginClass);
                Constructor<AbstractPluginMessageStore> construct = clazz.getConstructor(MessageStorePluginContext.class, MessageStore.class);
                messageStore = construct.newInstance(context, messageStore);
            } catch (Throwable e) {
                throw new RuntimeException(String.format(
                    "Initialize plugin's class %s not found!", pluginClass), e);
            }
        }
    }
    return messageStore;
}
 
Example #10
Source File: TransactionalMessageBridge.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public TransactionalMessageBridge(BrokerController brokerController, MessageStore store) {
    try {
        this.brokerController = brokerController;
        this.store = store;
        this.storeHost =
            new InetSocketAddress(brokerController.getBrokerConfig().getBrokerIP1(),
                brokerController.getNettyServerConfig().getListenPort());
    } catch (Exception e) {
        LOGGER.error("Init TransactionBridge error", e);
        throw new RuntimeException(e);
    }

}
 
Example #11
Source File: MessageStoreTestBase.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
protected void doGetMessages(MessageStore messageStore, String topic, int queueId, int num, long beginLogicsOffset) {
    for (int i = 0; i < num; i++) {
        GetMessageResult getMessageResult =  messageStore.getMessage("group", topic, queueId, beginLogicsOffset + i, 3, null);
        Assert.assertNotNull(getMessageResult);
        Assert.assertTrue(!getMessageResult.getMessageBufferList().isEmpty());
        MessageExt messageExt = MessageDecoder.decode(getMessageResult.getMessageBufferList().get(0));
        Assert.assertEquals(beginLogicsOffset + i, messageExt.getQueueOffset());
        getMessageResult.release();
    }
}
 
Example #12
Source File: MessageStoreTestBase.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
protected void doPutMessages(MessageStore messageStore, String topic, int queueId, int num, long beginLogicsOffset) throws UnknownHostException {
    for (int i = 0; i < num; i++) {
        MessageExtBrokerInner msgInner = buildMessage();
        msgInner.setTopic(topic);
        msgInner.setQueueId(queueId);
        PutMessageResult putMessageResult = messageStore.putMessage(msgInner);
        Assert.assertEquals(PutMessageStatus.PUT_OK, putMessageResult.getPutMessageStatus());
        Assert.assertEquals(beginLogicsOffset + i, putMessageResult.getAppendMessageResult().getLogicsOffset());
    }
}
 
Example #13
Source File: TransactionalMessageBridge.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public TransactionalMessageBridge(BrokerController brokerController, MessageStore store) {
    try {
        this.brokerController = brokerController;
        this.store = store;
        this.storeHost =
            new InetSocketAddress(brokerController.getBrokerConfig().getBrokerIP1(),
                brokerController.getNettyServerConfig().getListenPort());
    } catch (Exception e) {
        LOGGER.error("Init TransactionBridge error", e);
        throw new RuntimeException(e);
    }

}
 
Example #14
Source File: TransactionalMessageBridge.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public TransactionalMessageBridge(BrokerController brokerController, MessageStore store) {
    try {
        this.brokerController = brokerController;
        this.store = store;
        this.storeHost =
            new InetSocketAddress(brokerController.getBrokerConfig().getBrokerIP1(),
                brokerController.getNettyServerConfig().getListenPort());
    } catch (Exception e) {
        LOGGER.error("Init TransactionBridge error", e);
        throw new RuntimeException(e);
    }

}
 
Example #15
Source File: BrokerController.java    From rocketmq_trans_message with Apache License 2.0 4 votes vote down vote up
public void setMessageStore(MessageStore messageStore) {
    this.messageStore = messageStore;
}
 
Example #16
Source File: AbstractPluginMessageStore.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public AbstractPluginMessageStore(MessageStorePluginContext context, MessageStore next) {
    this.next = next;
    this.context = context;
}
 
Example #17
Source File: AbstractPluginMessageStore.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public AbstractPluginMessageStore(MessageStorePluginContext context, MessageStore next) {
    this.next = next;
    this.context = context;
}
 
Example #18
Source File: BrokerController.java    From rocketmq_trans_message with Apache License 2.0 4 votes vote down vote up
public MessageStore getMessageStore() {
    return messageStore;
}
 
Example #19
Source File: AbstractPluginMessageStore.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
public AbstractPluginMessageStore(MessageStorePluginContext context, MessageStore next) {
    this.next = next;
    this.context = context;
}
 
Example #20
Source File: BrokerController.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public MessageStore getMessageStore() {
    return messageStore;
}
 
Example #21
Source File: BrokerController.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public void setMessageStore(MessageStore messageStore) {
    this.messageStore = messageStore;
}
 
Example #22
Source File: BrokerController.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
public void setMessageStore(MessageStore messageStore) {
    this.messageStore = messageStore;
}
 
Example #23
Source File: BrokerController.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
public MessageStore getMessageStore() {
    return messageStore;
}
 
Example #24
Source File: AbstractPluginMessageStore.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public AbstractPluginMessageStore(MessageStorePluginContext context, MessageStore next) {
    this.next = next;
    this.context = context;
}
 
Example #25
Source File: BrokerController.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public void setMessageStore(MessageStore messageStore) {
    this.messageStore = messageStore;
}
 
Example #26
Source File: BrokerController.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public MessageStore getMessageStore() {
    return messageStore;
}
 
Example #27
Source File: BrokerController.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public MessageStore getMessageStore() {
    return messageStore;
}
 
Example #28
Source File: BrokerController.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public void setMessageStore(MessageStore messageStore) {
    this.messageStore = messageStore;
}
 
Example #29
Source File: BrokerController.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public MessageStore getMessageStore() {
    return messageStore;
}
 
Example #30
Source File: AbstractPluginMessageStore.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
public AbstractPluginMessageStore(MessageStorePluginContext context, MessageStore next) {
    this.next = next;
    this.context = context;
}