• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ConnectionFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.nats.client.ConnectionFactory的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactory类的具体用法?Java ConnectionFactory怎么用?Java ConnectionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ConnectionFactory类属于io.nats.client包,在下文中一共展示了ConnectionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: start

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
@Override
public void start(Map<String, String> map) {
  LOG.info("Start the Nats Sink Task");
  String[] nhost = map.get(NATS_URL).split(",");
  this.subject = map.get(NATS_SUBJECT);
  try {
    if (nhost.length == 1)
      this.nc = Nats.connect(nhost[0]);
    else{
      ConnectionFactory cf = new ConnectionFactory();
      cf.setServers(nhost);
      cf.setMaxReconnect(5);
      cf.setReconnectWait(2000);
      cf.setNoRandomize(true);
      this.nc = cf.createConnection();
    }
    LOG.info("Connected to the next NATS URL(master) : " + this.nc.getConnectedUrl());
  } catch (IOException e){
    LOG.error(e.getMessage(), e);
  }
}
 
开发者ID:oystparis,项目名称:kafka-connect-nats,代码行数:22,代码来源:NatsSinkTask.java


示例2: onStartup

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
@Override
public boolean onStartup(Logger logger, ConnectionFactory factory) {
    this.logger = logger;

    try {
        loadProperties();
        loadConfig();
        initJedis();
    }
    catch (Exception e) {
        logger.error("Unable to initialize.", e);
        teardownJedis();
        return false;
    }

    return true;
}
 
开发者ID:nats-io,项目名称:nats-connector-redis,代码行数:18,代码来源:RedisPubSubPlugin.java


示例3: run

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
@Override
public void run() {

	try {
		logger.info("NATS Subscriber ({}):  Subscribing to subject: {}", id, subject); //trace

		io.nats.client.Connection c = new ConnectionFactory(natsUrl).createConnection();

		AsyncSubscription s = c.subscribeAsync(subject, this);
		s.start();

		setReady();

		logger.info("NATS Subscriber ({}):  Subscribing to subject: {}", id, subject); // debug

		waitForCompletion();

		s.unsubscribe();

		logger.info("NATS Subscriber ({}):  Exiting.", id); // debug
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
	}
}
 
开发者ID:Logimethods,项目名称:nats-connector-spark,代码行数:27,代码来源:StandardNatsSubscriber.java


示例4: start

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
@Override
public void start(Map<String, String> map) {
  LOG.info("Start the Nats Source Task");
  String nsubject = map.get(NATS_SUBJECT);
  String[] nhost = map.get(NATS_URL).split(",");
  String nQueueGroup = map.get(NATS_QUEUE_GROUP);
  this.ktopic = map.get(KAFKA_TOPIC);
  try {
    if (nhost.length == 1)
      this.nc = Nats.connect(nhost[0]);
    else if (nhost.length >= 2){
      ConnectionFactory cf = new ConnectionFactory();
      cf.setServers(nhost);
      cf.setMaxReconnect(5);
      cf.setReconnectWait(2000);
      cf.setNoRandomize(true);
      this.nc = cf.createConnection();
    }
    else
      throw new ConnectException("No NATS URL");
    LOG.info("Connected to the next NATS URL(master) : " + this.nc.getConnectedUrl());
  } catch (IOException e){
    throw new ConnectException(e.getMessage(), e);
  }

  this.nc.subscribe(nsubject, nQueueGroup, message -> {
    LOG.debug("Sending the next message : {}", message);
    Schema recordSchema = NatsSourceConverter.getRecordSchema();
    Struct recordStruct = NatsSourceConverter.getRecordStruct(recordSchema, message.getReplyTo(),
            new String(message.getData()));
    SourceRecord sc = new SourceRecord(null,null,
            ktopic ,Schema.STRING_SCHEMA, message.getSubject(),
            recordSchema, recordStruct);
    mQueue.add(sc);
  });
}
 
开发者ID:oystparis,项目名称:kafka-connect-nats,代码行数:37,代码来源:NatsSourceTask.java


示例5: receive

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
/** Create a socket connection and receive data until receiver is stopped 
 * @throws IncompleteException 
 * @throws TimeoutException 
 * @throws IOException 
 * @throws Exception **/
protected void receive() throws IncompleteException, IOException, TimeoutException {

	// Make connection and initialize streams			  
	final ConnectionFactory connectionFactory = new ConnectionFactory(getEnrichedProperties());
	final Connection connection = connectionFactory.createConnection();
	logger.info("A NATS from '{}' to Spark Connection has been created for '{}', sharing Queue '{}'.", connection.getConnectedUrl(), this, queue);
	
	for (String subject: getSubjects()) {
		final Subscription sub = connection.subscribe(subject, queue, getMessageHandler());
		logger.info("Listening on {}.", subject);
		
		Runtime.getRuntime().addShutdownHook(new Thread(new Runnable(){
			@Override
			public void run() {
				logger.debug("Caught CTRL-C, shutting down gracefully..." + this);
				try {
					sub.unsubscribe();
				} catch (IOException e) {
					if (logger.isDebugEnabled()) {
						logger.error("Exception while unsubscribing " + e.toString());
					}
				}
				connection.close();
			}
		}));
	}
}
 
开发者ID:Logimethods,项目名称:nats-connector-spark,代码行数:33,代码来源:OmnipotentStandardNatsToSparkConnector.java


示例6: run

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
@Override
public void run() {

	try {

		logger.debug("NATS Publisher ({}):  Starting", id);

		ConnectionFactory cf = new ConnectionFactory(natsUrl);
		io.nats.client.Connection c = cf.createConnection();
		
		logger.debug("A NATS Connection to '{}' has been created.", c.getConnectedUrl());
		
		setReady();

		for (int i = 0; i < testCount; i++) {
			final String payload = NATS_PAYLOAD + INCR.getAndIncrement();
			c.publish(subject, payload.getBytes());
			logger.trace("Publish '{}' to '{}'.", payload, subject);
			tallyMessage();
		}
		c.flush();

		logger.debug("NATS Publisher ({}):  Published {} messages.", id, testCount);

		setComplete();
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
	}
}
 
开发者ID:Logimethods,项目名称:nats-connector-spark,代码行数:32,代码来源:StandardNatsPublisher.java


示例7: run

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
@Override
public void run() {

	try {

		logger.debug("NATS Publisher ({}):  Starting", id);

		ConnectionFactory cf = new ConnectionFactory(natsUrl);
		io.nats.client.Connection c = cf.createConnection();
		
		logger.debug("A NATS Connection to '{}' has been created.", c.getConnectedUrl());
		
		setReady();

		for (int i = 0; i < testCount; i++) {
			final ByteBuffer buffer = ByteBuffer.allocate(4);
			final int payload = NATS_PAYLOAD_INT + INCR.getAndIncrement();
			buffer.putInt(payload);				
			c.publish(subject, buffer.array());
			logger.trace("Publish '{}' to '{}'.", payload, subject);
			tallyMessage();
		}
		c.flush();

		logger.debug("NATS Publisher ({}):  Published {} messages.", id, testCount);

		setComplete();
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
	}
}
 
开发者ID:Logimethods,项目名称:nats-connector-spark,代码行数:34,代码来源:IntegerNatsPublisher.java


示例8: SparkToStandardNatsConnectorImpl

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
/**
 * @param properties
 * @param connectionFactory
 * @param subjects
 * @param b 
 */
protected SparkToStandardNatsConnectorImpl(String natsURL, Properties properties, Long connectionTimeout, 
		ConnectionFactory connectionFactory, Collection<String> subjects, boolean isStoredAsKeyValue) {
	super(natsURL, properties, connectionTimeout, subjects);
	this.connectionFactory = connectionFactory;
	setStoredAsKeyValue(isStoredAsKeyValue);
}
 
开发者ID:Logimethods,项目名称:nats-connector-spark,代码行数:13,代码来源:SparkToStandardNatsConnectorImpl.java


示例9: testLoadConsumer

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
@Test
public void testLoadConsumer() throws InterruptedException, IOException, TimeoutException {
    mockResultEndpoint.setExpectedMessageCount(10000);
    ConnectionFactory cf = new ConnectionFactory("nats://localhost:4222");
    Connection connection = cf.createConnection();

    for (int i = 0; i < 10000; i++) {
        connection.publish("test", ("test" + i).getBytes());
    }

    mockResultEndpoint.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:NatsConsumerLoadTest.java


示例10: NatsClient

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
public NatsClient(String... servers) {
    cf = new ConnectionFactory();
    cf.setServers(servers);
}
 
开发者ID:datathings,项目名称:greycat,代码行数:5,代码来源:NatsClient.java


示例11: newDefaultConnection

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
static synchronized Connection newDefaultConnection() throws IOException, TimeoutException {
    return new ConnectionFactory().createConnection();
}
 
开发者ID:nats-io,项目名称:nats-connector-redis,代码行数:4,代码来源:UnitTestUtilities.java


示例12: getConnectionFactory

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
/**
 * @return the connectionFactory
 */
protected ConnectionFactory getConnectionFactory() {
	return connectionFactory;
}
 
开发者ID:Logimethods,项目名称:nats-connector-spark,代码行数:7,代码来源:AbstractSparkToStandardNatsConnectorPool.java


示例13: setConnectionFactory

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
/**
 * @param connectionFactory the connectionFactory to set
 */
protected void setConnectionFactory(ConnectionFactory factory) {
	connectionFactory = factory;
}
 
开发者ID:Logimethods,项目名称:nats-connector-spark,代码行数:7,代码来源:AbstractSparkToStandardNatsConnectorPool.java


示例14: getConnection

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
private Connection getConnection() throws TimeoutException, IOException {
    Properties prop = getEndpoint().getNatsConfiguration().createProperties();
    ConnectionFactory factory = new ConnectionFactory(prop);
    connection = factory.createConnection();
    return connection;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:7,代码来源:NatsProducer.java


示例15: getConnection

import io.nats.client.ConnectionFactory; //导入依赖的package包/类
private Connection getConnection() throws IOException, InterruptedException, TimeoutException {
    Properties prop = getEndpoint().getNatsConfiguration().createProperties();
    ConnectionFactory factory = new ConnectionFactory(prop);
    connection = factory.createConnection();
    return connection;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:7,代码来源:NatsConsumer.java



注:本文中的io.nats.client.ConnectionFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Nodes类代码示例发布时间:2022-05-23
下一篇:
Java Device类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap