io.nats.client.ConnectionFactory Java Examples
The following examples show how to use
io.nats.client.ConnectionFactory.
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: NATSEventQueueProvider.java From conductor with Apache License 2.0 | 6 votes |
@Inject public NATSEventQueueProvider(Configuration config) { logger.info("NATS Event Queue Provider init"); // Init NATS API. Handle "io_nats" and "io.nats" ways to specify parameters Properties props = new Properties(); Properties temp = new Properties(); temp.putAll(System.getenv()); temp.putAll(System.getProperties()); temp.forEach((key1, value) -> { String key = key1.toString(); String val = value.toString(); if (key.startsWith("io_nats")) { key = key.replace("_", "."); } props.put(key, config.getProperty(key, val)); }); // Init NATS API factory = new ConnectionFactory(props); logger.info("NATS Event Queue Provider initialized..."); }
Example #2
Source File: DataFlowHandler.java From nats-connector-framework with Apache License 2.0 | 6 votes |
private void setup() throws Exception { connectionFactory = new ConnectionFactory(properties); EventHandlers eh = new EventHandlers(); connectionFactory.setClosedCallback(eh); connectionFactory.setDisconnectedCallback(eh); connectionFactory.setExceptionHandler(eh); connectionFactory.setReconnectedCallback(eh); // invoke on startup here, so the user can override or set their // own callbacks in the plugin if need be. if (invokeOnStartup(connectionFactory) == false) { shutdown(); throw new Exception("Startup failure initiated From plug-in"); } connection = connectionFactory.createConnection(); logger.debug("Connected to NATS cluster."); }
Example #3
Source File: DataFlowHandler.java From nats-connector-framework with Apache License 2.0 | 6 votes |
private void setup() throws Exception { connectionFactory = new ConnectionFactory(properties); EventHandlers eh = new EventHandlers(); connectionFactory.setClosedCallback(eh); connectionFactory.setDisconnectedCallback(eh); connectionFactory.setExceptionHandler(eh); connectionFactory.setReconnectedCallback(eh); // invoke on startup here, so the user can override or set their // own callbacks in the plugin if need be. if (invokeOnStartup(connectionFactory) == false) { shutdown(); throw new Exception("Startup failure initiated From plug-in"); } connection = connectionFactory.createConnection(); logger.debug("Connected to NATS cluster."); }
Example #4
Source File: NATSTestPlugin.java From nats-connector-framework with Apache License 2.0 | 5 votes |
private void testConnectorAPIs() throws Exception { MessageHandler mh = new MessageHandler() { @Override public void onMessage(Message message) { ;; } }; // test various combinatitions of subscribes and unsubscribes. connector.subscribe("foo1"); connector.subscribe("foo1"); connector.subscribe("foo2", mh); connector.subscribe("foo2", mh); connector.subscribe("foo3", "qg1"); connector.subscribe("foo3", "qg1"); connector.subscribe("foo4", "qg1", mh); connector.unsubscribe("foo1"); connector.unsubscribe("foo2"); connector.unsubscribe("foo3"); connector.unsubscribe("foo4"); connector.unsubscribe("foo4"); connector.unsubscribe("unknown"); connector.unsubscribe(null); connector.flush(); Connection c = connector.getConnection(); if (c == null) throw new Exception("Expected a valid connection."); ConnectionFactory cf = connector.getConnectionFactory(); if (cf == null) throw new Exception("Expected a valid connection."); }
Example #5
Source File: DataFlowHandler.java From nats-connector-framework with Apache License 2.0 | 5 votes |
private boolean invokeOnStartup(ConnectionFactory factory) { logger.debug("OnStartup"); try { return plugin.onStartup(LoggerFactory.getLogger(plugin.getClass().getName()), factory); } catch (Exception e) { logger.error("Runtime exception thrown by plugin (OnStartup): ", e); return false; } }
Example #6
Source File: DataFlowHandler.java From nats-connector-framework with Apache License 2.0 | 5 votes |
private boolean invokeOnStartup(ConnectionFactory factory) { logger.debug("OnStartup"); try { return plugin.onStartup(LoggerFactory.getLogger(plugin.getClass().getName()), factory); } catch (Exception e) { logger.error("Runtime exception thrown by plugin (OnStartup): ", e); return false; } }
Example #7
Source File: NATSTestPlugin.java From nats-connector-framework with Apache License 2.0 | 5 votes |
private void testConnectorAPIs() throws Exception { MessageHandler mh = new MessageHandler() { @Override public void onMessage(Message message) { ;; } }; // test various combinatitions of subscribes and unsubscribes. connector.subscribe("foo1"); connector.subscribe("foo1"); connector.subscribe("foo2", mh); connector.subscribe("foo2", mh); connector.subscribe("foo3", "qg1"); connector.subscribe("foo3", "qg1"); connector.subscribe("foo4", "qg1", mh); connector.unsubscribe("foo1"); connector.unsubscribe("foo2"); connector.unsubscribe("foo3"); connector.unsubscribe("foo4"); connector.unsubscribe("foo4"); connector.unsubscribe("unknown"); connector.unsubscribe(null); connector.flush(); Connection c = connector.getConnection(); if (c == null) throw new Exception("Expected a valid connection."); ConnectionFactory cf = connector.getConnectionFactory(); if (cf == null) throw new Exception("Expected a valid connection."); }
Example #8
Source File: UnitTestUtilities.java From nats-connector-framework with Apache License 2.0 | 4 votes |
static synchronized Connection newDefaultConnection() throws IOException, TimeoutException { return new ConnectionFactory().createConnection(); }
Example #9
Source File: NatsClient.java From greycat with Apache License 2.0 | 4 votes |
public NatsClient(String... servers) { cf = new ConnectionFactory(); cf.setServers(servers); }
Example #10
Source File: NATSTestPlugin.java From nats-connector-framework with Apache License 2.0 | 4 votes |
@Override public boolean onStartup(Logger logger, ConnectionFactory factory) { this.logger = logger; return true; }
Example #11
Source File: ExceptionTestPlugin.java From nats-connector-framework with Apache License 2.0 | 4 votes |
@Override public boolean onStartup(Logger logger, ConnectionFactory factory) { this.logger = logger; throw new RuntimeException("This is an exception from onStartup"); }
Example #12
Source File: DataFlowHandler.java From nats-connector-framework with Apache License 2.0 | 4 votes |
public ConnectionFactory getConnectionFactory() { return connectionFactory; }
Example #13
Source File: UnitTestUtilities.java From nats-connector-framework with Apache License 2.0 | 4 votes |
static synchronized Connection newDefaultConnection() throws IOException, TimeoutException { return new ConnectionFactory().createConnection(); }
Example #14
Source File: NATSTestPlugin.java From nats-connector-framework with Apache License 2.0 | 4 votes |
@Override public boolean onStartup(Logger logger, ConnectionFactory factory) { this.logger = logger; return true; }
Example #15
Source File: ExceptionTestPlugin.java From nats-connector-framework with Apache License 2.0 | 4 votes |
@Override public boolean onStartup(Logger logger, ConnectionFactory factory) { this.logger = logger; throw new RuntimeException("This is an exception from onStartup"); }
Example #16
Source File: DataFlowHandler.java From nats-connector-framework with Apache License 2.0 | 4 votes |
public ConnectionFactory getConnectionFactory() { return connectionFactory; }
Example #17
Source File: NATSObservableQueue.java From conductor with Apache License 2.0 | 4 votes |
public NATSObservableQueue(ConnectionFactory factory, String queueURI) { super(queueURI, "nats"); this.fact = factory; open(); }
Example #18
Source File: NATSConnectorPlugin.java From nats-connector-framework with Apache License 2.0 | 2 votes |
/** * Invoked when the connector is started up, before a connection * to the NATS cluster is made. The NATS connection factory is * valid at this time, providing an opportunity to alter * NATS connection parameters based on other plugin variables. * * @param logger - logger for the NATS connector process. * @param factory - the NATS connection factory. * @return - true if the connector should continue, false otherwise. */ public boolean onStartup(Logger logger, ConnectionFactory factory);
Example #19
Source File: NATSConnector.java From nats-connector-framework with Apache License 2.0 | 2 votes |
/*** * Advanced API to get the Connection Factory, This allows for NATS functionality beyond * the interface here. * * @return The NATS connector ConnectionFactory */ public ConnectionFactory getConnectionFactory();
Example #20
Source File: NATSConnector.java From nats-connector-framework with Apache License 2.0 | 2 votes |
/*** * Advanced API to get the Connection Factory, This allows for NATS functionality beyond * the interface here. * * @return The NATS connector ConnectionFactory */ public ConnectionFactory getConnectionFactory();
Example #21
Source File: NATSConnectorPlugin.java From nats-connector-framework with Apache License 2.0 | 2 votes |
/** * Invoked when the connector is started up, before a connection * to the NATS cluster is made. The NATS connection factory is * valid at this time, providing an opportunity to alter * NATS connection parameters based on other plugin variables. * * @param logger - logger for the NATS connector process. * @param factory - the NATS connection factory. * @return - true if the connector should continue, false otherwise. */ public boolean onStartup(Logger logger, ConnectionFactory factory);