當前位置: 首頁>>代碼示例>>Java>>正文


Java Message.body方法代碼示例

本文整理匯總了Java中org.vertx.java.core.eventbus.Message.body方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.body方法的具體用法?Java Message.body怎麽用?Java Message.body使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.vertx.java.core.eventbus.Message的用法示例。


在下文中一共展示了Message.body方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handle

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
/**
 * Handle the event bus reply.
 *
 * @param event The event
 */
@Override
public void handle(final AsyncResult<Message<Object>> event) {
	EventBusBridgeResponse response = new EventBusBridgeResponse();
	response.setSuccessful(event.succeeded());
	response.setAddress(address);
	if (event.succeeded()) {
		Message<Object> result = event.result();

		Object responseMessage = result.body();
		response.setResponseMessage(EventBusMessageTypeConverter.convertOutgoingMessage(result.body()));
		response.setEventBusMessageType(EventBusMessageType.lookupByClass(responseMessage.getClass()));
	} else {
		Throwable cause = event.cause();
		if (cause != null) {
			if (cause instanceof ReplyException) {
				ReplyException replyException = (ReplyException) cause;
				response.setCause(replyException.failureType().name());
			} else {
				response.setCause(cause.getMessage());
			}
		}
	}
	postResponse(response);
}
 
開發者ID:j2ro,項目名稱:mod-http-event-bus-bridge,代碼行數:30,代碼來源:HttpResponseHandler.java

示例2: processRequest

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
public void processRequest(Message<JsonObject> msg) {
    JsonObject request = msg.body();
    
    // MANDATORY: action to perform
    String action = helper.getMandatoryString(request, MSG_PROPERTY_ACTION, msg);
    if (action == null) return;

    // OPTIONAL: headers to use for the operation
    JsonObject headers = helper.getOptionalObject(request, MSG_PROPERTY_HEADERS);

    // OPTIONAL: timeout for the action (defaults to 10sec)
    int timeout = helper.getOptionalInt(request, MSG_PROPERTY_TIMEOUT, DEFAULT_REQUEST_TIMEOUT);
    
    // OPTIONAL: database on which the action should be performed (will default to the database specified in the config or _system if none was specified)
    String dbName = helper.getOptionalString(request, MSG_PROPERTY_DATABASE, persistor.SETTING_DBNAME);
    
    performAction(msg, action, headers, timeout, dbName);
}
 
開發者ID:santo74,項目名稱:vertx-arangodb,代碼行數:19,代碼來源:AbstractRestAPI.java

示例3: prepare

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
/**
 * From a retrieved message prepare the given arguments to prepared statements and cache them
 * 
 * @param message
 */
@SuppressWarnings("unchecked")
private void prepare(Message<JsonObject> message) {
	JsonObject prepareMessage = message.body();

	try {
		if(prepareMessage.containsField("statement")) {
			getPreparedStatementCache().add(prepareMessage.getString("statement"));

		} else {
			// Note: If more statements than cache size are entered, the
			// ladder will replace the earlier
			getPreparedStatementCache().addAll(prepareMessage.getArray("statements").toList());
		}

	} catch(Exception e) {
		// An error happened
		sendError(message, "[Cassandra Persistor] Could not prepare query/ies from " + prepareMessage + "!", e);
		return;
	}

	//
	sendOK(message);
}
 
開發者ID:nea,項目名稱:vertx-mod-cassandra-persistor,代碼行數:29,代碼來源:CassandraPersistor.java

示例4: unlock

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
private void unlock(Message<JsonObject> message) throws InterruptedException, ExecutionException {
  JsonObject json = message.body(); 
  
  String key = getMandatoryString("key", message);   
  Long cas = json.getLong("cas");
  
  if (key == null || cas == null) {
    sendError(message, "key and cas must be specified");
    return;
  }
      
  OperationFuture<Boolean> unlockFuture = client.asyncUnlock(key, cas);
  boolean response = unlockFuture.get();
  
  if (response) {
    JsonObject reply = new JsonObject();
    reply.putString("key", unlockFuture.getKey());
    sendOK(message, reply);
  }
  else {
    sendError(message, unlockFuture.getStatus().getMessage());
  }
}
 
開發者ID:jmusacchio,項目名稱:mod-couchbase-persistor,代碼行數:24,代碼來源:CouchbasePersistor.java

示例5: touch

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
private void touch(Message<JsonObject> message) throws InterruptedException, ExecutionException {
  JsonObject json = message.body(); 
  
  String key = getMandatoryString("key", message);   
  int expiration = json.getInteger("expiration", 0);
  
  if (key == null) {
    sendError(message, "key must be specified");
    return;
  }
      
  OperationFuture<Boolean> touchFuture = client.touch(key, expiration);
  boolean response = touchFuture.get();
  
  if (response) {
    JsonObject reply = new JsonObject();
    reply.putString("key", touchFuture.getKey());
    sendOK(message, reply);
  }
  else {
    sendError(message, touchFuture.getStatus().getMessage());
  }
}
 
開發者ID:jmusacchio,項目名稱:mod-couchbase-persistor,代碼行數:24,代碼來源:CouchbasePersistor.java

示例6: saveVertex

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
private void saveVertex(Message<JsonObject> message) {
  try {
    JsonObject mBody = message.body();
    String id = mBody.getString("id");
    JsonObject props = mBody.getObject("properties");

    og = factory.getTx();

    Vertex v = og.getVertex(id);
    props.getFieldNames().forEach(
      (fieldName) ->
        v.setProperty(fieldName, props.getValue(fieldName))
    );

    og.commit();

    JsonObject reply = new JsonObject(getVertexAsMap(v, true));

    sendOK(message, reply);
  } catch (Exception e) {
    logger.error(e);
    sendError(message, e.toString());
    og.rollback();
  }
}
 
開發者ID:jeremiahrhall,項目名稱:orientdb-persistor,代碼行數:26,代碼來源:OrientDBPersistor.java

示例7: addVertex

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
private void addVertex(Message<JsonObject> message) {
  try {
    JsonObject mBody = message.body();
    String clazz = mBody.getString("class");
    String cluster = mBody.getString("cluster", null);
    JsonObject props = mBody.getObject("properties");

    og = factory.getTx();

    Vertex newVertex = og.addVertex(clazz, cluster);
    props.getFieldNames().forEach(
      (fieldName) ->
        newVertex.setProperty(fieldName, props.getValue(fieldName))
    );

    og.commit();

    JsonObject reply = new JsonObject(getVertexAsMap(newVertex, true));

    sendOK(message, reply);
  } catch (Exception e) {
    logger.error(e);
    sendError(message, e.toString());
    og.rollback();
  }
}
 
開發者ID:jeremiahrhall,項目名稱:orientdb-persistor,代碼行數:27,代碼來源:OrientDBPersistor.java

示例8: handleLocalMessage

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
@Override
protected void handleLocalMessage(final Message events) {

    JsonArray jsonEvents = (JsonArray) events.body();

    for (int i = 0; i < jsonEvents.size(); i++) {

        JsonObject event = jsonEvents.get(i);

        String eventId = event.getString(EVENT_FIELD_ID, "");
        String title = event.getString(EVENT_FIELD_TITLE, "");
        String message = event.getString(EVENT_FIELD_MESSAGE, "");

        logger().trace("Processing notification: {}", eventId);

        // Event priority
        String priority = event.getString(EVENT_FIELD_PRIORITY,
                EVENT_PRIORITY_NORMAL);

        // Destinations
        JsonArray destinations = event.getArray(EVENT_FIELD_DESTINATIONS,
                new JsonArray());

        // Bombs away...
        send(eventId,
                destinations,
                title,
                message,
                priority);
    }
}
 
開發者ID:clidev,項目名稱:spike.x,代碼行數:32,代碼來源:Dispatcher.java

示例9: handle

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
@Override
public void handle(final Message<JsonObject> message) {
    Result result = new Result(message.body());
    if (!result.isReturnCode(RET_DEPLOYMENT_ID)) {
        throw new IllegalStateException(result.getReason());
    } else {
        m_filter.setDeploymentId(result.getReason());
    }
}
 
開發者ID:clidev,項目名稱:spike.x,代碼行數:10,代碼來源:Activator.java

示例10: processCommand

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
protected void processCommand(final Message message) {
    Object msgBody = message.body();
    if (msgBody instanceof JsonObject) {
        JsonObject json = (JsonObject) msgBody;
        logger().debug("Received command: {}", json);
        AbstractCommand cmd = buildCommand(json);
        cmd.execute(message);
    }
}
 
開發者ID:clidev,項目名稱:spike.x,代碼行數:10,代碼來源:AbstractActivator.java

示例11: handle

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
@Override
public void handle(final Message<JsonObject> message) {
    Commands.Result result = new Commands.Result(message.body());
    if (!result.isReturnCode(RET_DEPLOYMENT_ID)) {
        handleFailure(result);
    } else {
        String deploymentId = result.getReason();
        handleSuccess(deploymentId);
    }
}
 
開發者ID:clidev,項目名稱:spike.x,代碼行數:11,代碼來源:AbstractActivator.java

示例12: sendMessageToKinesis

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
protected void sendMessageToKinesis(final Message<JsonObject> event) throws KinesisException {
	if (kinesisAsyncClient == null) {
		throw new KinesisException("AmazonKinesisAsyncClient is not initialized");
	}

	if (!isValid(event.body().getString(PAYLOAD))) {
		logger.error("Invalid message provided.");
		return;
	}

	JsonObject object = event.body();
	logger.debug(" --- Got event " + event.toString());
	logger.debug(" --- Got body + " + object.toString());

	byte[] payload = object.getBinary(PAYLOAD);

	if (payload == null) {
		logger.debug(" --- Payload is null, trying to get the payload as String");
		payload = object.getString(PAYLOAD).getBytes();
	}
	logger.debug("Binary payload size: " + payload.length);

	String msgPartitionKey = object.getString(PARTITION_KEY);
	String requestPartitionKey = msgPartitionKey != null ? msgPartitionKey : partitionKey;

	PutRecordRequest putRecordRequest = new PutRecordRequest();
	putRecordRequest.setStreamName(streamName);
	putRecordRequest.setPartitionKey(requestPartitionKey);

	logger.debug("Writing to streamName " + streamName + " using partitionkey " + requestPartitionKey);

	putRecordRequest.setData(ByteBuffer.wrap(payload));

       retryCounter = 0;
	this.sendUsingAsyncClient(putRecordRequest, event);
}
 
開發者ID:awin,項目名稱:mod-kinesis,代碼行數:37,代碼來源:KinesisMessageProcessor.java

示例13: serviceUnRegisterHandler

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
private void serviceUnRegisterHandler(Message<JsonObject> message) {
    final JsonObject info = message.body();
    JSONTool.getObjectListFromArray(info.getArray("operations")).forEach(operation -> {
        final String url = operation.getString("url");
        if (registeredRoutes.contains(url)) {
            routeMatcher.removeAll(url);
            registeredRoutes.remove(url);
        }
    });
}
 
開發者ID:amoAHCP,項目名稱:vert.x-spring-microservice-demo,代碼行數:11,代碼來源:RestEntryVerticle.java

示例14: validResult

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
public static Either<String, JsonObject> validResult(Message<JsonObject> res) {
	if ("ok".equals(res.body().getString("status"))) {
		JsonObject r = res.body().getObject("result");
		if (r == null) {
			r = res.body();
			r.removeField("status");
		}
		return new Either.Right<>(r);
	} else {
		return new Either.Left<>(res.body().getString("message", ""));
	}
}
 
開發者ID:web-education,項目名稱:web-utils,代碼行數:13,代碼來源:Utils.java

示例15: handle

import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
/**
 * 
 */
@Override
public void handle(Message<JsonArray> message) {
	//
	JsonArray actions = message.body();
	BatchRequestHandler<?> batchRequestHandler = new BatchRequestHandler<>(message, actions.size());
	//
	for(int i = 0; i < actions.size(); i++) {
		eb.sendWithTimeout(getPersistorAddress(), (JsonObject) actions.get(i), getTimeout(), batchRequestHandler);
	}
}
 
開發者ID:nea,項目名稱:vertx-mod-cassandra-persistor,代碼行數:14,代碼來源:BatchActionsProcessor.java


注:本文中的org.vertx.java.core.eventbus.Message.body方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。