本文整理汇总了Java中com.aliyun.openservices.ons.api.SendResult类的典型用法代码示例。如果您正苦于以下问题:Java SendResult类的具体用法?Java SendResult怎么用?Java SendResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SendResult类属于com.aliyun.openservices.ons.api包,在下文中一共展示了SendResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: publish
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
@Override
public EasyTransMsgPublishResult publish(String topic, String tag, String key, Map<String,Object> header, byte[] msgByte) {
byte[] headerBytes = serializer.serialization(header);
int headerBytesLen = headerBytes.length;
int messageByteLen = msgByte.length;
byte[] combine = new byte[headerBytesLen + messageByteLen];
System.arraycopy(headerBytes, 0, combine, 0, headerBytes.length);
System.arraycopy(msgByte, 0, combine, headerBytes.length , msgByte.length);
Message message = new Message(topic, tag, key, combine);
Properties properties = new Properties();
properties.put(HEADER_LEN, headerBytesLen);
properties.put(MESSAGE_LEN, messageByteLen);
message.setUserProperties(properties);
SendResult send = producer.send(message);
EasyTransMsgPublishResult easyTransMsgPublishResult = new EasyTransMsgPublishResult();
easyTransMsgPublishResult.setTopic(send.getTopic());
easyTransMsgPublishResult.setMessageId(send.getMessageId());
return easyTransMsgPublishResult;
}
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:21,代码来源:OnsEasyTransMsgPublisherImpl.java
示例2: run
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
@Override
public void run(String... args) throws Exception {
producerFactory.sendAsync(TestProducer.DISH_ADD, new Dish(1L, "name"));
// producerFactory.sendAsync(TestProducer.DISH_UPDATE,
// new Dish(2L, "name"),
// new DeliveryOption("key").setDeliverTime(System.currentTimeMillis() + 1000 * 60));
//
// producerFactory.sendAsync(TestProducer.DISH_DEL, 1L, new SendCallback() {
// @Override
// public void onSuccess(SendResult sendResult) {
// //send success
// //do some thing...
// }
//
// @Override
// public void onException(OnExceptionContext context) {
// //send fail
// //do some thing...
// }
// });
SendResult sendResult = producerFactory.orderSend(OrderProducer.SEND_MAIL,"message","shardingKey");
//
//
}
开发者ID:onepiecex,项目名称:mq-aliyun,代码行数:26,代码来源:Application.java
示例3: sendMessage
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
@Override
public SendResult sendMessage(SimpleMessage onsMessage, SendMessageErrorHandler<SendResult> errorHandler){
Message message = onsMessage.toMessage();
String topic = resolvePlaceholders(message.getTopic());
message.setTopic(topic);
String tag = resolvePlaceholders(message.getTag());
message.setTag(tag);
Object body = onsMessage.getBody();
if(needSerialize(body)){
message.setBody(this.messageSerializer.serialize(onsMessage.getBody(), new MessageDelegate(message)));
}else{
message.setBody((byte[])body);
}
return sendRawMessage(message, errorHandler);
}
开发者ID:wayshall,项目名称:onetwo,代码行数:19,代码来源:ONSProducerServiceImpl.java
示例4: testSendMessage
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
@Test
public void testSendMessage(){
SendResult res = onsProducerService.sendMessage(SimpleMessage.builder()
.topic(TOPIC)
.tags(ORDER_PAY)
.key("1")
.body(OrderTestMessage.builder()
.orderId(1L)
.title("支付")
.build())
.build());
System.out.println("res: " + res);
res = onsProducerService.sendMessage(SimpleMessage.builder()
.topic(TOPIC)
.tags(ORDER_CANCEL)
.key("1")
.body(OrderTestMessage.builder()
.orderId(1L)
.title("取消")
.build())
.build());
System.out.println("res: " + res);
// LangUtils.CONSOLE.exitIf("test");
}
开发者ID:wayshall,项目名称:onetwo,代码行数:26,代码来源:RmqONSProducerTest.java
示例5: sendAsync
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
/**
* 发送异步消息,异步Callback形式
* @param message 消息
*/
public void sendAsync(com.yaoa.hibatis.mq.Message message){
Message onsMsg = createONSMessage(message);
producer.sendAsync(onsMsg, new SendCallback() {
public void onSuccess(SendResult sendResult) {
}
public void onException(OnExceptionContext context) {
logger.error("发送消息[" + context.getMessageId() +"] 失败" , context.getException());
}
});
}
开发者ID:yaoakeji,项目名称:hibatis,代码行数:18,代码来源:AliMessageProducer.java
示例6: sendByte
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
public SendResult sendByte(String topic, String tags, String keys, byte[] message) throws MQException {
Message msg = new Message(topic, tags, keys, message);
try {
return producer.send(msg);
} catch (Exception e) {
throw new MQException(e);
}
}
开发者ID:xushaomin,项目名称:apple-jms,代码行数:9,代码来源:RocketMessageProducer5.java
示例7: sendObject
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
public SendResult sendObject(String topic, String tags, String keys, Serializable message) throws MQException {
Message msg = new Message(topic, tags, ByteUtils.toBytes(message));
try {
return producer.send(msg);
} catch (Exception e) {
throw new MQException(e);
}
}
开发者ID:xushaomin,项目名称:apple-jms,代码行数:9,代码来源:RocketMessageProducer5.java
示例8: sendText
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
public SendResult sendText(String topic, String tags, String keys, String message) throws MQException {
Message msg = new Message(topic, tags, ByteUtils.toBytes(message));
try {
return producer.send(msg);
} catch (Exception e) {
throw new MQException(e);
}
}
开发者ID:xushaomin,项目名称:apple-jms,代码行数:9,代码来源:RocketMessageProducer5.java
示例9: sendByte
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
public void sendByte(byte[] message) throws JmsException {
Message msg = new Message(topic, tag, key, message);
try {
SendResult result = producer.send(msg);
logger.info("msgId=" + result.getMessageId());
} catch (Exception e) {
logger.error(e.getMessage());
throw new MQException(e);
}
}
开发者ID:xushaomin,项目名称:apple-jms,代码行数:11,代码来源:RocketMessageProducer.java
示例10: sendObject
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
@Override
public void sendObject(Serializable message) throws JmsException {
Message msg = new Message(topic, tag, key, ByteUtils.toBytes(message));
try {
SendResult result = producer.send(msg);
logger.info("msgId=" + result.getMessageId());
} catch (Exception e) {
logger.error(e.getMessage());
throw new MQException(e);
}
}
开发者ID:xushaomin,项目名称:apple-jms,代码行数:12,代码来源:RocketMessageProducer.java
示例11: sendText
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
@Override
public void sendText(String message) throws JmsException {
Message msg = new Message(topic, tag, key, ByteUtils.toBytes(message));
try {
SendResult result = producer.send(msg);
logger.info("msgId=" + result.getMessageId());
} catch (Exception e) {
logger.error(e.getMessage());
throw new MQException(e);
}
}
开发者ID:xushaomin,项目名称:apple-jms,代码行数:12,代码来源:RocketMessageProducer.java
示例12: handleException
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
protected Optional<SendResult> handleException(Throwable e, Message message, SendMessageErrorHandler<SendResult> errorHandler){
String errorMsg = "send message error. topic:"+message.getTopic()+", tags:"+message.getTag();
logger.error(errorMsg);
if(errorHandler!=null){
return errorHandler.onError(e);
}else if(e instanceof ONSClientException){
throw (ONSClientException)e;
}else{
throw new ServiceException("发送消息失败", e);
}
}
开发者ID:wayshall,项目名称:onetwo,代码行数:12,代码来源:ONSProducerServiceImpl.java
示例13: sendMessage
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
@Override
public SendResult sendMessage(SimpleMessage onsMessage, LocalTransactionExecuter executer, Object arg, SendMessageErrorHandler<SendResult> errorHandler){
Message message = onsMessage.toMessage();
String topic = SpringUtils.resolvePlaceholders(applicationContext, message.getTopic());
message.setTopic(topic);
Object body = onsMessage.getBody();
if(needSerialize(body)){
message.setBody(this.messageSerializer.serialize(onsMessage.getBody(), new MessageDelegate(message)));
}else{
message.setBody((byte[])body);
}
return sendRawMessage(message, executer, arg, errorHandler);
}
开发者ID:wayshall,项目名称:onetwo,代码行数:14,代码来源:ONSTransactionProducerServiceImpl.java
示例14: afterSendMessage
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
@Override
public void afterSendMessage(Message message, SendResult sendResult) {
if(logger.isInfoEnabled()){
logger.info("send message success. topic: {}, tags: {}, sendResult: {}", message.getTopic(), message.getTag(), sendResult);
}
for(ProducerListener<Message> listener : listeners){
listener.afterSendMessage(message, sendResult);
}
}
开发者ID:wayshall,项目名称:onetwo,代码行数:10,代码来源:ONSProducerListenerComposite.java
示例15: execute
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
public void execute(Tuple tuple) {
// TODO Auto-generated method stub
OnsTuple msgTuple = (OnsTuple)tuple.getValue(0);
long before = System.currentTimeMillis();
SendResult sendResult = null;
try {
Message msg = new Message(
producerConfig.getTopic(),
producerConfig.getSubExpress(),
//Message Body
//�κζ�������ʽ�����ݣ�ONS�����κθ�Ԥ����ҪProducer��ConsumerЭ�̺�һ�µ����л��ͷ����л���ʽ
msgTuple.getMessage().getBody());
// ���ô�����Ϣ��ҵ��ؼ����ԣ��뾡����ȫ��Ψһ��
// �Է��������������յ���Ϣ����£���ͨ��ONS Console��ѯ��Ϣ��������
// ע�⣺������Ҳ����Ӱ����Ϣ�����շ�
if (msgTuple.getMessage().getKey() != null) {
msg.setKey(msgTuple.getMessage().getKey());
}
//������Ϣ��ֻҪ�����쳣���dzɹ�
sendResult = producer.send(msg);
LOG.info("Success send msg of " + msgTuple.getMessage().getMsgID());
runCounter.count(System.currentTimeMillis() - before);
} catch (Exception e) {
LOG.error("Failed to send message, SendResult:" + sendResult + "\n", e);
runCounter.count(System.currentTimeMillis() - before);
collector.fail(tuple);
return ;
//throw new FailedException(e);
}
collector.ack(tuple);
}
开发者ID:kkllwww007,项目名称:jstrom,代码行数:35,代码来源:ProducerBolt.java
示例16: execute
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
public void execute(Tuple tuple) {
// TODO Auto-generated method stub
OnsTuple msgTuple = (OnsTuple)tuple.getValue(0);
long before = System.currentTimeMillis();
SendResult sendResult = null;
try {
Message msg = new Message(
producerConfig.getTopic(),
producerConfig.getSubExpress(),
//Message Body
//任何二进制形式的数据,ONS不做任何干预,需要Producer与Consumer协商好一致的序列化和反序列化方式
msgTuple.getMessage().getBody());
// 设置代表消息的业务关键属性,请尽可能全局唯一。
// 以方便您在无法正常收到消息情况下,可通过ONS Console查询消息并补发。
// 注意:不设置也不会影响消息正常收发
if (msgTuple.getMessage().getKey() != null) {
msg.setKey(msgTuple.getMessage().getKey());
}
//发送消息,只要不抛异常就是成功
sendResult = producer.send(msg);
LOG.info("Success send msg of " + msgTuple.getMessage().getMsgID());
runCounter.count(System.currentTimeMillis() - before);
} catch (Exception e) {
LOG.error("Failed to send message, SendResult:" + sendResult + "\n", e);
runCounter.count(System.currentTimeMillis() - before);
collector.fail(tuple);
return ;
//throw new FailedException(e);
}
collector.ack(tuple);
}
开发者ID:alibaba,项目名称:jstorm,代码行数:35,代码来源:ProducerBolt.java
示例17: send
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
public SendResult send(Message message) {
return producer.send(message);
}
开发者ID:xushaomin,项目名称:apple-jms,代码行数:4,代码来源:RocketMQProducer.java
示例18: sendMessage
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
SendResult sendMessage(SimpleMessage onsMessage,
LocalTransactionExecuter executer, Object arg);
开发者ID:wayshall,项目名称:onetwo,代码行数:3,代码来源:TransactionProducerService.java
示例19: setErrorHandler
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
public void setErrorHandler(SendMessageErrorHandler<SendResult> errorHandler) {
this.errorHandler = errorHandler;
}
开发者ID:wayshall,项目名称:onetwo,代码行数:4,代码来源:ONSProducerServiceImpl.java
示例20: orderSend
import com.aliyun.openservices.ons.api.SendResult; //导入依赖的package包/类
SendResult orderSend(final Enum address, final Object message, final String shardingKey);
开发者ID:onepiecex,项目名称:mq-aliyun,代码行数:2,代码来源:ProducerFactory.java
注:本文中的com.aliyun.openservices.ons.api.SendResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论