org.vertx.java.core.json.JsonObject Java Examples
The following examples show how to use
org.vertx.java.core.json.JsonObject.
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: DataStoreVerticle.java From boon with Apache License 2.0 | 6 votes |
public void start() { logger.info("Data Store Service Starting"); try { config = DataStoreServerConfig.load(); dataStoreServer.init(config); JsonObject configOverrides = container.config(); if (configOverrides.containsField("port")) { config.port(configOverrides.getInteger("port")); } puts("SERVER CONFIG", config.port()); configureAndStartHttpServer(dataStoreServer.getServicesDefinition()); } catch (Throwable ex) { logger.error(ex, "Data Store Service Starting FAILED"); } }
Example #2
Source File: KafkaMessageProcessorIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Test public void shouldReceiveMessage() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.putString(EventProperties.PAYLOAD, "foobar"); jsonObject.putString(EventProperties.PART_KEY, "bar"); Handler<Message<JsonObject>> replyHandler = new Handler<Message<JsonObject>>() { public void handle(Message<JsonObject> message) { assertEquals("ok", message.body().getString("status")); } }; vertx.eventBus().send(ADDRESS, jsonObject, replyHandler); wait.until(new RunnableAssert("shouldReceiveMessage") { @Override public void run() throws Exception { assertThat(messagesReceived.contains("foobar"), is(true)); } }); testComplete(); }
Example #3
Source File: KafkaMessageProcessorIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { before(); JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); KafkaMessageProcessorIT.super.start(); } }); }
Example #4
Source File: KafkaModuleDeployWithIncorrectConfigIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { VertxAssert.initialize(vertx); JsonObject config = new JsonObject(); // Do not put required config param when deploying the module - config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.failed()); assertEquals("address must be specified in config for busmod", asyncResult.cause().getMessage()); testComplete(); } }); }
Example #5
Source File: KafkaModuleDeployWithStatsdDisabledConfigIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); config.putBoolean("statsd.enabled", false); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); KafkaModuleDeployWithStatsdDisabledConfigIT.super.start(); } }); }
Example #6
Source File: KafkaMessageProcessorTest.java From mod-kafka with Apache License 2.0 | 6 votes |
@Test public void sendMessageToKafkaVerifyStatsDExecutorCalled() { KafkaMessageProcessor kafkaMessageProcessorSpy = spy(kafkaMessageProcessor); when(kafkaMessageProcessorSpy.getTopic()).thenReturn("default-topic"); when(kafkaMessageProcessorSpy.getSerializerType()).thenReturn(MessageSerializerType.STRING_SERIALIZER); JsonObject jsonObjectMock = mock(JsonObject.class); when(event.body()).thenReturn(jsonObjectMock); when(jsonObjectMock.getString(EventProperties.TOPIC)).thenReturn(""); when(jsonObjectMock.getString(EventProperties.PAYLOAD)).thenReturn("test payload"); StringMessageHandler messageHandler = mock(StringMessageHandler.class); when(messageHandlerFactory.createMessageHandler(any(MessageSerializerType.class))). thenReturn(messageHandler); kafkaMessageProcessorSpy.sendMessageToKafka(producer, event); verify(statsDClient, times(1)).recordExecutionTime(anyString(), anyLong()); }
Example #7
Source File: StringSerializerIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); container.logger().info("modulename: " +System.getProperty("vertx.modulename")); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); StringSerializerIT.super.start(); } }); }
Example #8
Source File: KafkaMessageProcessorTest.java From mod-kafka with Apache License 2.0 | 6 votes |
@Test public void sendMessageToKafkaWithTopic() { KafkaMessageProcessor kafkaMessageProcessorSpy = spy(kafkaMessageProcessor); when(kafkaMessageProcessorSpy.getTopic()).thenReturn("default-topic"); when(kafkaMessageProcessorSpy.getSerializerType()).thenReturn(MessageSerializerType.STRING_SERIALIZER); JsonObject jsonObjectMock = mock(JsonObject.class); String messageSpecificTopic = "foo-topic"; when(event.body()).thenReturn(jsonObjectMock); when(jsonObjectMock.getString(EventProperties.TOPIC)).thenReturn(messageSpecificTopic); when(jsonObjectMock.getString(EventProperties.PAYLOAD)).thenReturn("test payload"); when(jsonObjectMock.getString(EventProperties.PART_KEY)).thenReturn("test partition key"); StringMessageHandler messageHandler = mock(StringMessageHandler.class); when(messageHandlerFactory.createMessageHandler(any(MessageSerializerType.class))). thenReturn(messageHandler); kafkaMessageProcessorSpy.sendMessageToKafka(producer, event); verify(messageHandler, times(1)).send(producer, messageSpecificTopic, "test partition key", event.body()); }
Example #9
Source File: KafkaMessageProcessorTest.java From mod-kafka with Apache License 2.0 | 6 votes |
@Test public void sendMessageToKafka() { KafkaMessageProcessor kafkaMessageProcessorSpy = spy(kafkaMessageProcessor); when(kafkaMessageProcessorSpy.getTopic()).thenReturn("default-topic"); when(kafkaMessageProcessorSpy.getSerializerType()).thenReturn(MessageSerializerType.STRING_SERIALIZER); JsonObject jsonObjectMock = mock(JsonObject.class); when(event.body()).thenReturn(jsonObjectMock); when(jsonObjectMock.getString(EventProperties.TOPIC)).thenReturn(""); when(jsonObjectMock.getString(EventProperties.PAYLOAD)).thenReturn("test payload"); when(jsonObjectMock.getString(EventProperties.PART_KEY)).thenReturn("test partition key"); StringMessageHandler messageHandler = mock(StringMessageHandler.class); when(messageHandlerFactory.createMessageHandler(any(MessageSerializerType.class))). thenReturn(messageHandler); kafkaMessageProcessorSpy.sendMessageToKafka(producer, event); verify(messageHandler, times(1)).send(producer, "default-topic", "test partition key", event.body()); }
Example #10
Source File: KafkaModuleDeployWithCorrectConfigIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); KafkaModuleDeployWithCorrectConfigIT.super.start(); } }); }
Example #11
Source File: ByteArraySerializerIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.BYTE_SERIALIZER.getValue()); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); ByteArraySerializerIT.super.start(); } }); }
Example #12
Source File: KafkaModuleDeployWithStatsdEnabledConfigIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); config.putBoolean("statsd.enabled", true); config.putString("statsd.host", "localhost"); config.putNumber("statsd.port", 8125); config.putString("statsd.prefix", "testapp.prefix"); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); KafkaModuleDeployWithStatsdEnabledConfigIT.super.start(); } }); }
Example #13
Source File: ChannelBridge.java From realtime-channel with Apache License 2.0 | 6 votes |
public void bridge(final CountingCompletionHandler<Void> countDownLatch) { HttpServer server = vertx.createHttpServer(); SockJSServer sjsServer = vertx.createSockJSServer(server).setHook(hook); JsonObject empty = new JsonObject(); JsonArray all = new JsonArray().add(empty); JsonArray inboundPermitted = config.getArray("inbound_permitted", all); JsonArray outboundPermitted = config.getArray("outbound_permitted", all); sjsServer.bridge(config.getObject("sjs_config", new JsonObject() .putString("prefix", "/channel")), inboundPermitted, outboundPermitted, config.getObject( "bridge_config", empty)); countDownLatch.incRequired(); server.listen(config.getInteger("port", 1986), config.getString("host", "0.0.0.0"), new AsyncResultHandler<HttpServer>() { @Override public void handle(AsyncResult<HttpServer> ar) { if (!ar.succeeded()) { countDownLatch.failed(ar.cause()); } else { countDownLatch.complete(); } } }); }
Example #14
Source File: VertXBean.java From bookapp-cqrs with Apache License 2.0 | 6 votes |
public void start() { RouteMatcher routeMatcher = new RouteMatcher(); // HTTP server HttpServer httpServer = vertx.createHttpServer(); httpServer.requestHandler(routeMatcher); // SockJS server JsonArray permitted = new JsonArray(); permitted.add(new JsonObject()); // Let everything through SockJSServer sockJSServer = vertx.createSockJSServer(httpServer); sockJSServer.bridge(new JsonObject().putString("prefix", "/eventbus"), permitted, permitted); httpServer.listen(7777); System.out.println("Vert.X Core UP"); }
Example #15
Source File: PhpTypes.java From mod-lang-php with MIT License | 6 votes |
/** * Converts a JSON array to a PHP array. * * @param env The Quercus environment. * @param json A Vert.x json array. * @return A populated PHP array. */ public static ArrayValue arrayFromJson(Env env, JsonArray json) { ArrayValue result = new ArrayValueImpl(); Iterator<Object> iter = json.iterator(); while (iter.hasNext()) { Object value = iter.next(); if (value instanceof JsonObject) { result.put(PhpTypes.arrayFromJson(env, (JsonObject) value)); } else if (value instanceof JsonArray) { result.put(PhpTypes.arrayFromJson(env, (JsonArray) value)); } else { result.put(env.wrapJava(iter.next())); } } return result; }
Example #16
Source File: PhpTypes.java From mod-lang-php with MIT License | 6 votes |
/** * Converts a JSON object to a PHP array. * * @param env The Quercus environment. * @param json A Vert.x json object. * @return A populated PHP array. */ public static ArrayValue arrayFromJson(Env env, JsonObject json) { ArrayValue result = new ArrayValueImpl(); Map<String, Object> map = json.toMap(); Iterator<String> iter = map.keySet().iterator(); while (iter.hasNext()) { String key = iter.next(); Object value = map.get(key); if (value instanceof JsonObject) { result.put(env.createString(key), PhpTypes.arrayFromJson(env, (JsonObject) value));; } else if (value instanceof JsonArray) { result.put(env.createString(key), PhpTypes.arrayFromJson(env, (JsonArray) value));; } else { result.put(env.createString(key), env.wrapJava(value)); } } return result; }
Example #17
Source File: VertxBus.java From realtime-channel with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") static Object unwrapMsg(Object vertxMessage) { if (vertxMessage instanceof JsonObject) { return new JreJsonObject(((JsonObject) vertxMessage).toMap()); } else if (vertxMessage instanceof JsonArray) { return new JreJsonArray(((JsonArray) vertxMessage).toList()); } else { return vertxMessage; } }
Example #18
Source File: VertxBus.java From realtime-channel with Apache License 2.0 | 5 votes |
static Object wrapMsg(Object realtimeMessage) { if (realtimeMessage instanceof JreJsonObject) { return new JsonObject(((JreJsonObject) realtimeMessage).toNative()); } else if (realtimeMessage instanceof JreJsonArray) { return new JsonArray(((JreJsonArray) realtimeMessage).toNative()); } else { return realtimeMessage; } }
Example #19
Source File: BridgeHook.java From realtime-channel with Apache License 2.0 | 5 votes |
@Override public boolean handleSendOrPub(SockJSSocket sock, boolean send, JsonObject msg, final String topic) { if (WebSocketBus.TOPIC_CONNECT.equals(topic)) { connections.put(sock.writeHandlerID(), msg.getObject("body").getString(WebSocketBus.SESSION)); } else if (msg.getValue("body") instanceof JsonObject) { JsonObject body = msg.getObject("body"); if (!body.containsField(WebSocketBus.SESSION)) { body.putString(WebSocketBus.SESSION, connections.get(sock.writeHandlerID())); } } return true; }
Example #20
Source File: StringSerializerIT.java From mod-kafka with Apache License 2.0 | 5 votes |
@Test(expected = FailedToSendMessageException.class) public void sendMessage() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.putString(EventProperties.PAYLOAD, MESSAGE); Handler<Message<JsonObject>> replyHandler = new Handler<Message<JsonObject>>() { public void handle(Message<JsonObject> message) { assertEquals("error", message.body().getString("status")); assertTrue(message.body().getString("message").equals("Failed to send message to Kafka broker...")); testComplete(); } }; vertx.eventBus().send(ADDRESS, jsonObject, replyHandler); }
Example #21
Source File: BookEventListener.java From bookapp-cqrs with Apache License 2.0 | 5 votes |
@EventHandler public void on(BookAddedEvent event) { System.out.println("VertX listener reveived book added event for: " + event.getTitle() + " (" + event.getBookId() + ")"); JsonObject paylod = new JsonObject(); paylod.putString("eventId", EVENT_BOOK_ADDED); paylod.putString("bookId", event.getBookId()); paylod.putString("bookTitle", event.getTitle()); paylod.putNumber("releaseDate", event.getReleaseDate().getTime()); paylod.putString("authorId", event.getAuthorId()); vertxBean.getEventBus().publish(CLIENT_ADDRESS, paylod); }
Example #22
Source File: BookEventListener.java From bookapp-cqrs with Apache License 2.0 | 5 votes |
@EventHandler public void on(BookRemovedEvent event) { System.out.println("VertX listener reveived book removed event for: " + event.getBookId()); JsonObject paylod = new JsonObject(); paylod.putString("eventId", EVENT_BOOK_REMOVED); paylod.putString("bookId", event.getBookId()); vertxBean.getEventBus().publish(CLIENT_ADDRESS,paylod); }
Example #23
Source File: BookEventListener.java From bookapp-cqrs with Apache License 2.0 | 5 votes |
@EventHandler public void on(BookTitleChangedEvent event) { System.out.println("VertX listener reveived book title cahnged event for: " + event.getBookId()); JsonObject paylod = new JsonObject(); paylod.putString("eventId", EVENT_BOOK_TITLE_CHANGED); paylod.putString("bookId", event.getBookId()); paylod.putString("newBookTitle", event.getNewTitle()); vertxBean.getEventBus().publish(CLIENT_ADDRESS,paylod); }
Example #24
Source File: AuthorEventListener.java From bookapp-cqrs with Apache License 2.0 | 5 votes |
@EventHandler public void on(AuthorAddedEvent event) { System.out.println("VertX listener reveived author added event for: " + event.getFirstname() + " " +event.getLastname() + " (" + event.getAuthorId() + ")"); JsonObject paylod = new JsonObject(); paylod.putString("eventId", EVENT_AUTHOR_ADDED); paylod.putString("authorId", event.getAuthorId()); paylod.putString("firstname", event.getFirstname()); paylod.putString("lastname", event.getLastname()); vertxBean.getEventBus().publish(CLIENT_ADDRESS, paylod); }
Example #25
Source File: AuthorEventListener.java From bookapp-cqrs with Apache License 2.0 | 5 votes |
@EventHandler public void on(AuthorRemovedEvent event) { System.out.println("VertX listener reveived author removed event for: " + event.getAuthorId()); JsonObject paylod = new JsonObject(); paylod.putString("eventId", EVENT_AUTHOR_REMOVED); paylod.putString("authorId", event.getAuthorId()); vertxBean.getEventBus().publish(CLIENT_ADDRESS,paylod); }
Example #26
Source File: KafkaModuleDeployWithStatsdDisabledConfigIT.java From mod-kafka with Apache License 2.0 | 5 votes |
@Test(expected = FailedToSendMessageException.class) public void sendMessageStatsDDisabled() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.putString(EventProperties.PAYLOAD, MESSAGE); Handler<Message<JsonObject>> replyHandler = new Handler<Message<JsonObject>>() { public void handle(Message<JsonObject> message) { assertEquals("error", message.body().getString("status")); assertTrue(message.body().getString("message").equals("Failed to send message to Kafka broker...")); testComplete(); } }; vertx.eventBus().send(ADDRESS, jsonObject, replyHandler); }
Example #27
Source File: KafkaModuleDeployWithCorrectConfigIT.java From mod-kafka with Apache License 2.0 | 5 votes |
@Test(expected = FailedToSendMessageException.class) public void sendMessage() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.putString(EventProperties.PAYLOAD, MESSAGE); Handler<Message<JsonObject>> replyHandler = new Handler<Message<JsonObject>>() { public void handle(Message<JsonObject> message) { assertEquals("error", message.body().getString("status")); assertTrue(message.body().getString("message").equals("Failed to send message to Kafka broker...")); testComplete(); } }; vertx.eventBus().send(ADDRESS, jsonObject, replyHandler); }
Example #28
Source File: ByteArraySerializerIT.java From mod-kafka with Apache License 2.0 | 5 votes |
@Test(expected = FailedToSendMessageException.class) public void sendMessage() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.putBinary(EventProperties.PAYLOAD, MESSAGE.getBytes()); Handler<Message<JsonObject>> replyHandler = new Handler<Message<JsonObject>>() { public void handle(Message<JsonObject> message) { assertEquals("error", message.body().getString("status")); assertTrue(message.body().getString("message").equals("Failed to send message to Kafka broker...")); testComplete(); } }; vertx.eventBus().send(ADDRESS, jsonObject, replyHandler); }
Example #29
Source File: KafkaModuleDeployWithStatsdEnabledConfigIT.java From mod-kafka with Apache License 2.0 | 5 votes |
@Test(expected = FailedToSendMessageException.class) public void sendMessageStatsDDisabled() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.putString(EventProperties.PAYLOAD, MESSAGE); Handler<Message<JsonObject>> replyHandler = new Handler<Message<JsonObject>>() { public void handle(Message<JsonObject> message) { assertEquals("error", message.body().getString("status")); assertTrue(message.body().getString("message").equals("Failed to send message to Kafka broker...")); testComplete(); } }; vertx.eventBus().send(ADDRESS, jsonObject, replyHandler); }
Example #30
Source File: KafkaMessageProcessor.java From mod-kafka with Apache License 2.0 | 5 votes |
/** * Sends messages to Kafka topic using specified properties in kafka.properties file. * * @param producer kafka producer provided by the caller * @param event event that should be sent to Kafka Broker */ protected void sendMessageToKafka(Producer producer, Message<JsonObject> event) { if (!isValid(event.body().getString(PAYLOAD))) { logger.error("Invalid kafka message provided. Message not sent to kafka..."); sendError(event, String.format("Invalid kafka message provided. Property [%s] is not set.", PAYLOAD)) ; return; } try { final MessageHandler messageHandler = messageHandlerFactory.createMessageHandler(serializerType); String topic = isValid(event.body().getString(TOPIC)) ? event.body().getString(TOPIC) : getTopic(); String partKey = event.body().getString(PART_KEY); long startTime = System.currentTimeMillis(); messageHandler.send(producer, topic, partKey, event.body()); statsDClient.recordExecutionTime("submitted", (System.currentTimeMillis()-startTime)); sendOK(event); logger.info(String.format("Message sent to kafka topic: %s. Payload: %s", topic, event.body().getString(PAYLOAD))); } catch (FailedToSendMessageException ex) { sendError(event, "Failed to send message to Kafka broker...", ex); } }