org.apache.avro.ipc.NettyTransceiver Java Examples
The following examples show how to use
org.apache.avro.ipc.NettyTransceiver.
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: AvroProtocol.java From dubbox with Apache License 2.0 | 6 votes |
@Override protected <T> T doRefer(Class<T> type, URL url) throws RpcException { logger.info("type => " + type.getName()); logger.info("url => " + url); try { NettyTransceiver client = new NettyTransceiver(new InetSocketAddress(url.getHost(), url.getPort())); T ref = ReflectRequestor.getClient(type, client); logger.info("Create Avro Client"); return ref; } catch (Exception e) { logger.error(e.getMessage(), e); throw new RpcException("Fail to create remoting client for service(" + url + "): " + e.getMessage(), e); } }
Example #2
Source File: CaseController.java From skywalking with Apache License 2.0 | 5 votes |
@RequestMapping("/healthCheck") @ResponseBody public String healthCheck() throws IOException { try { nettyClient = SpecificRequestor.getClient(Greeter.class, new NettyTransceiver(new InetSocketAddress("localhost", 9018))); return SUCCESS; } catch (Exception e) { throw e; } }
Example #3
Source File: ClientAvroRPC.java From netty-cookbook with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { if(args.length < 3){ args = new String[] {"[email protected]","[email protected]","Hello !"}; } NettyTransceiver client = new NettyTransceiver(new InetSocketAddress(10000)); Mail proxy = (Mail) SpecificRequestor.getClient(Mail.class, client); LogUtil.println("ClientAvroRPC built OK, got proxy, ready to send data ..."); Message message = new Message(); message.setTo(new Utf8(args[0])); message.setFrom(new Utf8(args[1])); message.setBody(new Utf8(args[2])); LogUtil.println("Calling proxy.send with message: " + message.toString()); LogUtil.println("Result from server: " + proxy.send(message)); client.close(); }
Example #4
Source File: ClientAvroRPC.java From netty-cookbook with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { if(args.length < 3){ args = new String[] {"[email protected]","[email protected]","Hello !"}; } NettyTransceiver client = new NettyTransceiver(new InetSocketAddress(10000)); Mail proxy = (Mail) SpecificRequestor.getClient(Mail.class, client); LogUtil.println("ClientAvroRPC built OK, got proxy, ready to send data ..."); Message message = new Message(); message.setTo(new Utf8(args[0])); message.setFrom(new Utf8(args[1])); message.setBody(new Utf8(args[2])); LogUtil.println("Calling proxy.send with message: " + message.toString()); LogUtil.println("Result from server: " + proxy.send(message)); client.close(); }
Example #5
Source File: AvroFileManagerClient.java From oodt with Apache License 2.0 | 5 votes |
public AvroFileManagerClient(final URL url, boolean testConnection) throws ConnectionException { //setup the and start the client try { this.fileManagerUrl = url; InetSocketAddress inetSocketAddress = new InetSocketAddress(url.getHost(), this.fileManagerUrl.getPort()); this.client = new NettyTransceiver(inetSocketAddress, 40000L); proxy = (AvroFileManager) SpecificRequestor.getClient(AvroFileManager.class, client); } catch (IOException e) { logger.error("Error occurred when creating file manager: {}", url, e); } if (testConnection && !isAlive()) { throw new ConnectionException("Exception connecting to filemgr: [" + this.fileManagerUrl + "]"); } }
Example #6
Source File: AvroRpcWorkflowManagerClient.java From oodt with Apache License 2.0 | 5 votes |
@Override public void setWorkflowManagerUrl(URL workflowManagerUrl) { this.workflowManagerUrl = workflowManagerUrl; try { client = new NettyTransceiver(new InetSocketAddress(workflowManagerUrl.getPort())); proxy = SpecificRequestor.getClient(org.apache.oodt.cas.workflow.struct.avrotypes.WorkflowManager.class, client); } catch (IOException e) { logger.error("Error occurred when setting workflow manager url: {}", workflowManagerUrl, e); } }
Example #7
Source File: TestTCPServerSource.java From datacollector with Apache License 2.0 | 4 votes |
@Test public void flumeAvroIpc() throws StageException, IOException, ExecutionException, InterruptedException { final Charset charset = Charsets.UTF_8; final TCPServerSourceConfig configBean = createConfigBean(charset); configBean.tcpMode = TCPMode.FLUME_AVRO_IPC; configBean.dataFormat = DataFormat.TEXT; configBean.bindAddress = "0.0.0.0"; final int batchSize = 5; final String outputLane = "output"; final TCPServerSource source = new TCPServerSource(configBean); final PushSourceRunner runner = new PushSourceRunner.Builder(TCPServerDSource.class, source) .addOutputLane(outputLane) .setOnRecordError(OnRecordError.TO_ERROR) .build(); runner.runInit(); runner.runProduce(Collections.emptyMap(), batchSize, out -> { final Map<String, List<Record>> outputMap = out.getRecords(); assertThat(outputMap, hasKey(outputLane)); final List<Record> records = outputMap.get(outputLane); assertThat(records, hasSize(batchSize)); for (int i = 0; i < batchSize; i++) { assertThat( records.get(i).get("/" + TextDataParserFactory.TEXT_FIELD_NAME), fieldWithValue(getFlumeAvroIpcEventName(i)) ); } runner.setStop(); }); final AvroSourceProtocol client = SpecificRequestor.getClient(AvroSourceProtocol.class, new NettyTransceiver(new InetSocketAddress("localhost", Integer.parseInt(configBean.ports.get(0))))); List<AvroFlumeEvent> events = new LinkedList<>(); for (int i = 0; i < batchSize; i++) { AvroFlumeEvent avroEvent = new AvroFlumeEvent(); avroEvent.setHeaders(new HashMap<CharSequence, CharSequence>()); avroEvent.setBody(ByteBuffer.wrap(getFlumeAvroIpcEventName(i).getBytes())); events.add(avroEvent); } Status status = client.appendBatch(events); assertThat(status, equalTo(Status.OK)); runner.waitOnProduce(); }
Example #8
Source File: TestAvroSource.java From mt-flume with Apache License 2.0 | 4 votes |
private void doRequest(boolean serverEnableCompression, boolean clientEnableCompression, int compressionLevel) throws InterruptedException, IOException { boolean bound = false; for (int i = 0; i < 100 && !bound; i++) { try { Context context = new Context(); context.put("port", String.valueOf(selectedPort = 41414 + i)); context.put("bind", "0.0.0.0"); context.put("threads", "50"); if (serverEnableCompression) { context.put("compression-type", "deflate"); } else { context.put("compression-type", "none"); } Configurables.configure(source, context); source.start(); bound = true; } catch (ChannelException e) { /* * NB: This assume we're using the Netty server under the hood and the * failure is to bind. Yucky. */ } } Assert .assertTrue("Reached start or error", LifecycleController.waitForOneOf( source, LifecycleState.START_OR_ERROR)); Assert.assertEquals("Server is started", LifecycleState.START, source.getLifecycleState()); AvroSourceProtocol client; if (clientEnableCompression) { client = SpecificRequestor.getClient( AvroSourceProtocol.class, new NettyTransceiver(new InetSocketAddress( selectedPort), new CompressionChannelFactory(6))); } else { client = SpecificRequestor.getClient( AvroSourceProtocol.class, new NettyTransceiver(new InetSocketAddress( selectedPort))); } AvroFlumeEvent avroEvent = new AvroFlumeEvent(); avroEvent.setHeaders(new HashMap<CharSequence, CharSequence>()); avroEvent.setBody(ByteBuffer.wrap("Hello avro".getBytes())); Status status = client.append(avroEvent); Assert.assertEquals(Status.OK, status); Transaction transaction = channel.getTransaction(); transaction.begin(); Event event = channel.take(); Assert.assertNotNull(event); Assert.assertEquals("Channel contained our event", "Hello avro", new String(event.getBody())); transaction.commit(); transaction.close(); logger.debug("Round trip event:{}", event); source.stop(); Assert.assertTrue("Reached stop or error", LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR)); Assert.assertEquals("Server is stopped", LifecycleState.STOP, source.getLifecycleState()); }
Example #9
Source File: TestAvroSource.java From mt-flume with Apache License 2.0 | 4 votes |
@Test public void testSslRequest() throws InterruptedException, IOException { boolean bound = false; for (int i = 0; i < 10 && !bound; i++) { try { Context context = new Context(); context.put("port", String.valueOf(selectedPort = 41414 + i)); context.put("bind", "0.0.0.0"); context.put("ssl", "true"); context.put("keystore", "src/test/resources/server.p12"); context.put("keystore-password", "password"); context.put("keystore-type", "PKCS12"); Configurables.configure(source, context); source.start(); bound = true; } catch (ChannelException e) { /* * NB: This assume we're using the Netty server under the hood and the * failure is to bind. Yucky. */ Thread.sleep(100); } } Assert .assertTrue("Reached start or error", LifecycleController.waitForOneOf( source, LifecycleState.START_OR_ERROR)); Assert.assertEquals("Server is started", LifecycleState.START, source.getLifecycleState()); AvroSourceProtocol client = SpecificRequestor.getClient( AvroSourceProtocol.class, new NettyTransceiver(new InetSocketAddress( selectedPort), new SSLChannelFactory())); AvroFlumeEvent avroEvent = new AvroFlumeEvent(); avroEvent.setHeaders(new HashMap<CharSequence, CharSequence>()); avroEvent.setBody(ByteBuffer.wrap("Hello avro ssl".getBytes())); Status status = client.append(avroEvent); Assert.assertEquals(Status.OK, status); Transaction transaction = channel.getTransaction(); transaction.begin(); Event event = channel.take(); Assert.assertNotNull(event); Assert.assertEquals("Channel contained our event", "Hello avro ssl", new String(event.getBody())); transaction.commit(); transaction.close(); logger.debug("Round trip event:{}", event); source.stop(); Assert.assertTrue("Reached stop or error", LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR)); Assert.assertEquals("Server is stopped", LifecycleState.STOP, source.getLifecycleState()); }