io.openmessaging.Future Java Examples
The following examples show how to use
io.openmessaging.Future.
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: AsyncProducer.java From joyqueue with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { KeyValue keyValue = OMS.newKeyValue(); keyValue.put(OMSBuiltinKeys.ACCOUNT_KEY, "test_token"); keyValue.put(JoyQueueBuiltinKeys.TRANSACTION_TIMEOUT, 1000 * 10); MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint("oms:joyqueue://[email protected]:50088/UNKNOWN", keyValue); Producer producer = messagingAccessPoint.createProducer(); producer.start(); Message message = producer.createMessage("test_topic_0", "body".getBytes()); Future<SendResult> future = producer.sendAsync(message); // future.addListener(new FutureListener<SendResult>() { //// @Override //// public void operationComplete(Future<SendResult> future) { //// System.out.println(future.get().messageId()); //// } //// }); System.out.println(future.get().messageId()); }
Example #2
Source File: AsyncBatchProducer.java From joyqueue with Apache License 2.0 | 6 votes |
public static void main(String[] args) { KeyValue keyValue = OMS.newKeyValue(); keyValue.put(OMSBuiltinKeys.ACCOUNT_KEY, "test_token"); MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint("oms:joyqueue://[email protected]:50088/UNKNOWN", keyValue); Producer producer = messagingAccessPoint.createProducer(); producer.start(); List<Message> messages = new ArrayList<>(); for (int i = 0; i < 10; i++) { Message message = producer.createMessage("test_topic_0", "body".getBytes()); messages.add(message); } Future<SendResult> future = producer.sendAsync(messages); // future.addListener(new FutureListener<SendResult>() { // @Override // public void operationComplete(Future<SendResult> future) { // System.out.println(future.get().messageId()); // } // }); System.out.println(future.get().messageId()); }
Example #3
Source File: BrokerBasedLog.java From openmessaging-connect-runtime with Apache License 2.0 | 6 votes |
@Override public void send(K key, V value){ try { byte[] messageBody = encodeKeyValue(key, value); if (messageBody.length > RuntimeConfigDefine.MAX_MESSAGE_SIZE) { log.error("Message size is greater than {} bytes, key: {}, value {}", RuntimeConfigDefine.MAX_MESSAGE_SIZE, key, value); return; } Future<SendResult> result = producer.sendAsync(producer.createBytesMessage(queueName, messageBody)); result.addListener((future) -> { if (future.getThrowable() != null) { log.error("Send async message Failed, error: {}", future.getThrowable()); } else { log.info("Send async message OK, msgId: {}", future.get().messageId() + "\n"); } }); } catch (Exception e) { log.error("BrokerBaseLog send async message Failed.", e); } }
Example #4
Source File: DefaultPromiseTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Test public void testAddListener() throws Exception { promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.get()).isEqualTo("Done"); } }); promise.set("Done"); }
Example #5
Source File: DefaultPromiseTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); promise.setFailure(exception); }
Example #6
Source File: DefaultPromiseTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException_ListenerAfterSet() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.setFailure(exception); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); }
Example #7
Source File: DefaultPromiseTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testAddListener_ListenerAfterSet() throws Exception { promise.set("Done"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(future.get()).isEqualTo("Done"); } }); }
Example #8
Source File: DefaultPromiseTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testAddListener() throws Exception { promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.get()).isEqualTo("Done"); } }); promise.set("Done"); }
Example #9
Source File: WorkerSourceTask.java From openmessaging-connect-runtime with Apache License 2.0 | 5 votes |
/** * Send list of sourceDataEntries to MQ. * @param sourceDataEntries */ private void sendRecord(Collection<SourceDataEntry> sourceDataEntries) { for(SourceDataEntry sourceDataEntry : sourceDataEntries){ ByteBuffer partition = sourceDataEntry.getSourcePartition(); ByteBuffer position = sourceDataEntry.getSourcePosition(); sourceDataEntry.setSourcePartition(null); sourceDataEntry.setSourcePosition(null); byte[] payload = recordConverter.objectToByte(sourceDataEntry.getPayload()); Object[] newPayload = new Object[1]; newPayload[0] = Base64.getEncoder().encodeToString(payload); sourceDataEntry.setPayload(newPayload); final byte[] messageBody = JSON.toJSONString(sourceDataEntry).getBytes(); if (messageBody.length > RuntimeConfigDefine.MAX_MESSAGE_SIZE) { log.error("Send record, message size is greater than {} bytes, payload: {}", RuntimeConfigDefine.MAX_MESSAGE_SIZE, sourceDataEntry.getPayload()); return; } Message sourceMessage = producer.createBytesMessage(sourceDataEntry.getQueueName(), messageBody); Future<SendResult> sendResult = producer.sendAsync(sourceMessage); sendResult.addListener((future) -> { if(null != future.getThrowable()){ log.error("Source task send record failed.", future.getThrowable()); }else{ try { // send ok if(null != partition && null != position){ positionData.put(partition, position); } } catch (Exception e) { log.error("Source task save position info failed.", e); } } }); } }
Example #10
Source File: DefaultPromiseTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); promise.setFailure(exception); }
Example #11
Source File: DefaultPromiseTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException_ListenerAfterSet() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.setFailure(exception); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); }
Example #12
Source File: DefaultPromiseTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Test public void testAddListener_ListenerAfterSet() throws Exception { promise.set("Done"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(future.get()).isEqualTo("Done"); } }); }
Example #13
Source File: DefaultPromiseTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Test public void testAddListener() throws Exception { promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.get()).isEqualTo("Done"); } }); promise.set("Done"); }
Example #14
Source File: DefaultPromiseTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); promise.setFailure(exception); }
Example #15
Source File: DefaultPromiseTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException_ListenerAfterSet() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.setFailure(exception); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); }
Example #16
Source File: DefaultPromiseTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Test public void testAddListener_ListenerAfterSet() throws Exception { promise.set("Done"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(future.get()).isEqualTo("Done"); } }); }
Example #17
Source File: TransactionProducerImpl.java From joyqueue with Apache License 2.0 | 4 votes |
@Override public Future<SendResult> sendAsync(Message message) { return delegate.sendAsync(message); }
Example #18
Source File: TransactionProducerImpl.java From joyqueue with Apache License 2.0 | 4 votes |
@Override public Future<SendResult> sendAsync(List<Message> messages) { return delegate.sendAsync(messages); }
Example #19
Source File: ProducerWrapper.java From joyqueue with Apache License 2.0 | 4 votes |
@Override public Future<SendResult> sendAsync(Message message) { return delegate.sendAsync(message); }
Example #20
Source File: ProducerWrapper.java From joyqueue with Apache License 2.0 | 4 votes |
@Override public Future<SendResult> sendAsync(List<Message> messages) { return delegate.sendAsync(messages); }
Example #21
Source File: SimpleProducer.java From rocketmq-read with Apache License 2.0 | 4 votes |
public static void main(String[] args) { final MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default"); final Producer producer = messagingAccessPoint.createProducer(); messagingAccessPoint.startup(); System.out.printf("MessagingAccessPoint startup OK%n"); producer.startup(); System.out.printf("Producer startup OK%n"); { Message message = producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8"))); SendResult sendResult = producer.send(message); //final Void aVoid = result.get(3000L); System.out.printf("Send async message OK, msgId: %s%n", sendResult.messageId()); } final CountDownLatch countDownLatch = new CountDownLatch(1); { final Future<SendResult> result = producer.sendAsync(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); result.addListener(new FutureListener<SendResult>() { @Override public void operationComplete(Future<SendResult> future) { if (future.getThrowable() != null) { System.out.printf("Send async message Failed, error: %s%n", future.getThrowable().getMessage()); } else { System.out.printf("Send async message OK, msgId: %s%n", future.get().messageId()); } countDownLatch.countDown(); } }); } { producer.sendOneway(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); System.out.printf("Send oneway message OK%n"); } try { countDownLatch.await(); Thread.sleep(500); // Wait some time for one-way delivery. } catch (InterruptedException ignore) { } producer.shutdown(); }
Example #22
Source File: SimpleProducer.java From rocketmq with Apache License 2.0 | 4 votes |
public static void main(String[] args) { final MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default"); final Producer producer = messagingAccessPoint.createProducer(); messagingAccessPoint.startup(); System.out.printf("MessagingAccessPoint startup OK%n"); producer.startup(); System.out.printf("Producer startup OK%n"); { Message message = producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8"))); SendResult sendResult = producer.send(message); //final Void aVoid = result.get(3000L); System.out.printf("Send async message OK, msgId: %s%n", sendResult.messageId()); } final CountDownLatch countDownLatch = new CountDownLatch(1); { final Future<SendResult> result = producer.sendAsync(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); result.addListener(new FutureListener<SendResult>() { @Override public void operationComplete(Future<SendResult> future) { if (future.getThrowable() != null) { System.out.printf("Send async message Failed, error: %s%n", future.getThrowable().getMessage()); } else { System.out.printf("Send async message OK, msgId: %s%n", future.get().messageId()); } countDownLatch.countDown(); } }); } { producer.sendOneway(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); System.out.printf("Send oneway message OK%n"); } try { countDownLatch.await(); Thread.sleep(500); // Wait some time for one-way delivery. } catch (InterruptedException ignore) { } producer.shutdown(); }
Example #23
Source File: SimpleProducer.java From rocketmq-4.3.0 with Apache License 2.0 | 4 votes |
public static void main(String[] args) { final MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default"); final Producer producer = messagingAccessPoint.createProducer(); messagingAccessPoint.startup(); System.out.printf("MessagingAccessPoint startup OK%n"); producer.startup(); System.out.printf("Producer startup OK%n"); { Message message = producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8"))); SendResult sendResult = producer.send(message); //final Void aVoid = result.get(3000L); System.out.printf("Send async message OK, msgId: %s%n", sendResult.messageId()); } final CountDownLatch countDownLatch = new CountDownLatch(1); { final Future<SendResult> result = producer.sendAsync(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); result.addListener(new FutureListener<SendResult>() { @Override public void operationComplete(Future<SendResult> future) { if (future.getThrowable() != null) { System.out.printf("Send async message Failed, error: %s%n", future.getThrowable().getMessage()); } else { System.out.printf("Send async message OK, msgId: %s%n", future.get().messageId()); } countDownLatch.countDown(); } }); } { producer.sendOneway(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); System.out.printf("Send oneway message OK%n"); } try { countDownLatch.await(); Thread.sleep(500); // Wait some time for one-way delivery. } catch (InterruptedException ignore) { } producer.shutdown(); }
Example #24
Source File: Producer.java From openmessaging-java with Apache License 2.0 | 2 votes |
/** * Sends a message to the specified destination asynchronously, the destination should be preset to {@link * Message#header()}, other header fields as well. * <p> * The returned {@code Promise} will have the result once the operation completes, and the registered {@code * FutureListener} will be notified, either because the operation was successful or because of an error. * * @param message a message will be sent. * @return the {@code Promise} of an asynchronous message send operation. * @see Future * @see FutureListener */ Future<SendResult> sendAsync(Message message);
Example #25
Source File: Producer.java From openmessaging-java with Apache License 2.0 | 2 votes |
/** * Send messages to the specified destination asynchronously, the destination should be preset to {@link * Message#header()}, other header fields as well. * <p> * The returned {@code Promise} will have the result once the operation completes, and the registered {@code * FutureListener} will be notified, either because the operation was successful or because of an error. * * @param messages a batch messages will be sent. * @return the {@code Promise} of an asynchronous messages send operation. * @see Future * @see FutureListener */ Future<SendResult> sendAsync(List<Message> messages);