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

Java EventHubClient类代码示例

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

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



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

示例1: sendToEventHub

import com.microsoft.azure.eventhubs.EventHubClient; //导入依赖的package包/类
private CompletableFuture<Void> sendToEventHub(String streamId, EventData eventData, Object partitionKey,
                                               EventHubClient eventHubClient) {
  if (PartitioningMethod.ROUND_ROBIN.equals(partitioningMethod)) {
    return eventHubClient.send(eventData);
  } else if (PartitioningMethod.EVENT_HUB_HASHING.equals(partitioningMethod)) {
    if (partitionKey == null) {
      throw new SamzaException("Partition key cannot be null for EventHub hashing");
    }
    return eventHubClient.send(eventData, convertPartitionKeyToString(partitionKey));
  } else if (PartitioningMethod.PARTITION_KEY_AS_PARTITION.equals(partitioningMethod)) {
    if (!(partitionKey instanceof Integer)) {
      String msg = "Partition key should be of type Integer";
      throw new SamzaException(msg);
    }

    Integer numPartition = streamPartitionSenders.get(streamId).size();
    Integer destinationPartition = (Integer) partitionKey % numPartition;

    PartitionSender sender = streamPartitionSenders.get(streamId).get(destinationPartition);
    return sender.send(eventData);
  } else {
    throw new SamzaException("Unknown partitioning method " + partitioningMethod);
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:25,代码来源:EventHubSystemProducer.java


示例2: AzureIoTService

import com.microsoft.azure.eventhubs.EventHubClient; //导入依赖的package包/类
/**
 * No-args constructor.
 */
public AzureIoTService() {
	if (!StringUtils.isBlank(SERVICE_ACCESS_KEY)) {
		if (!StringUtils.isBlank(EVENTHUB_ENDPOINT)) {
			final ArrayList<EventHubClient> recievers = new ArrayList<>();
			for (int i = 0; i < PARTITIONS_COUNT; i++) {
				recievers.add(receiveEventsAsync(Integer.toString(i)));
			}
			Para.addDestroyListener(new DestroyListener() {
				public void onDestroy() {
					for (EventHubClient recvr : recievers) {
						recvr.close();
					}
				}
			});
		}
		try {
			registryManager = RegistryManager.createFromConnectionString(SERVICE_CONN_STR);
		} catch (Exception ex) {
			logger.warn("Couldn't initialize Azure registry manager: {}", ex.getMessage());
		}
	}
}
 
开发者ID:Erudika,项目名称:para,代码行数:26,代码来源:AzureIoTService.java


示例3: consumeEvents

import com.microsoft.azure.eventhubs.EventHubClient; //导入依赖的package包/类
private static void consumeEvents(String ehName, String namespace, String keyName, String token)
    throws ServiceBusException, IOException, ExecutionException, InterruptedException {
  ConnectionStringBuilder connStr = new ConnectionStringBuilder(namespace, ehName, keyName, token);

  EventHubClient client = EventHubClient.createFromConnectionStringSync(connStr.toString());

  EventHubRuntimeInformation runTimeInfo = client.getRuntimeInformation().get();
  int numPartitions = runTimeInfo.getPartitionCount();
  for (int partition = 0; partition < numPartitions; partition++) {
    PartitionReceiver receiver =
        client.createReceiverSync(EventHubClient.DEFAULT_CONSUMER_GROUP_NAME, String.valueOf(partition),
            PartitionReceiver.START_OF_STREAM);
    receiver.receive(10).handle((records, throwable) -> handleComplete(receiver, records, throwable));
  }
}
 
开发者ID:srinipunuru,项目名称:samza-sql-tools,代码行数:16,代码来源:EventHubConsoleConsumer.java


示例4: init

import com.microsoft.azure.eventhubs.EventHubClient; //导入依赖的package包/类
@Override
public void init() {
  String remoteHost = String.format(EVENTHUB_REMOTE_HOST_FORMAT, eventHubNamespace);
  try {
    ConnectionStringBuilder connectionStringBuilder =
            new ConnectionStringBuilder(eventHubNamespace, entityPath, sasKeyName, sasKey);

    eventHubClient = EventHubClient.createFromConnectionStringSync(connectionStringBuilder.toString(), retryPolicy);
  } catch (IOException | ServiceBusException e) {
    String msg = String.format("Creation of EventHub client failed for eventHub EntityPath: %s on remote host %s:%d",
            entityPath, remoteHost, ClientConstants.AMQPS_PORT);
    LOG.error(msg, e);
    throw new SamzaException(msg, e);
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:16,代码来源:SamzaEventHubClientManager.java


示例5: testReceive

import com.microsoft.azure.eventhubs.EventHubClient; //导入依赖的package包/类
@Test
public void testReceive() throws ServiceBusException {
  EventHubClientManagerFactory clientFactory = new EventHubClientManagerFactory();
  EventHubClientManager wrapper = clientFactory
          .getEventHubClientManager(SYSTEM_NAME, STREAM_NAME1, new EventHubConfig(createEventHubConfig()));
  wrapper.init();
  EventHubClient client = wrapper.getEventHubClient();
  PartitionReceiver receiver =
          client.createReceiverSync(EventHubClient.DEFAULT_CONSUMER_GROUP_NAME, "0",
                  EventHubSystemConsumer.START_OF_STREAM, true);
  receiveMessages(receiver, 300);
}
 
开发者ID:apache,项目名称:samza,代码行数:13,代码来源:ITestEventHubSystemProducer.java


示例6: createEventHubClient

import com.microsoft.azure.eventhubs.EventHubClient; //导入依赖的package包/类
public EventHubClient createEventHubClient() throws IOException, ServiceBusException {
  ConnectionStringBuilder connStr = new ConnectionStringBuilder(
      commonConf.namespaceName,
      commonConf.eventHubName,
      commonConf.sasKeyName,
      commonConf.sasKey
  );
  return EventHubClient.createFromConnectionStringSync(connStr.toString());
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:10,代码来源:EventHubCommon.java


示例7: init

import com.microsoft.azure.eventhubs.EventHubClient; //导入依赖的package包/类
@Override
public List<ConfigIssue> init(Info info, Context context) {
  List<ConfigIssue> issues = new ArrayList<>();
  this.context = context;

  consumerConfigBean.dataFormatConfig.stringBuilderPoolSize = getNumberOfThreads();
  consumerConfigBean.dataFormatConfig.init(
      context,
      consumerConfigBean.dataFormat,
      Groups.DATA_FORMAT.name(),
      "dataFormatConfig",
      DataFormatConstants.MAX_OVERRUN_LIMIT,
      issues
  );
  parserFactory = consumerConfigBean.dataFormatConfig.getParserFactory();
  errorQueue = new ArrayBlockingQueue<>(100);
  errorList = new ArrayList<>(100);

  // validate the connection info
  if(issues.size() == 0) {
    try {
      EventHubClient ehClient = eventHubCommon.createEventHubClient();
      EventHubRuntimeInformation ehInfo = ehClient.getRuntimeInformation().get();
      ehClient.close().get();
    } catch (Exception e) {
      issues.add(context.createConfigIssue(
          Groups.EVENT_HUB.toString(),
          EventHubCommon.CONF_NAME_SPACE,
          Errors.EVENT_HUB_02,
          e.getMessage()
      ));
    }
  }

  return issues;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:37,代码来源:EventHubConsumerSource.java


示例8: receiveEventsAsync

import com.microsoft.azure.eventhubs.EventHubClient; //导入依赖的package包/类
private static EventHubClient receiveEventsAsync(final String partitionId) {
	EventHubClient client = null;
	try {
		client = EventHubClient.createFromConnectionStringSync(EVENTHUB_CONN_STR);
		client.createReceiver(EventHubClient.DEFAULT_CONSUMER_GROUP_NAME, partitionId, Instant.now()).
				thenAccept(new Receiver(partitionId));
	} catch (Exception e) {
		logger.warn("Couldn't start receiving messages from Azure cloud: {}", e.getMessage());
	}
	return client;
}
 
开发者ID:Erudika,项目名称:para,代码行数:12,代码来源:AzureIoTService.java


示例9: getEventHubClient

import com.microsoft.azure.eventhubs.EventHubClient; //导入依赖的package包/类
@Override
public EventHubClient getEventHubClient() {
  return eventHubClient;
}
 
开发者ID:apache,项目名称:samza,代码行数:5,代码来源:SamzaEventHubClientManager.java


示例10: getEventHubClient

import com.microsoft.azure.eventhubs.EventHubClient; //导入依赖的package包/类
/**
 * Returns the underlying {@link EventHubClient} instance. Multiple invocations
 * of this method should return the same instance instead of
 * creating new ones.
 *
 * @return EventHub client instance of the wrapper
 */
EventHubClient getEventHubClient();
 
开发者ID:apache,项目名称:samza,代码行数:9,代码来源:EventHubClientManager.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java SerializerReadClass类代码示例发布时间:2022-05-23
下一篇:
Java HCatFieldSchema类代码示例发布时间: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