use of com.google.api.services.cloudiot.v1.model.DeviceRegistry in project java-docs-samples by GoogleCloudPlatform.
the class DeviceRegistryExample method createRegistry.
// [START iot_create_registry]
/**
* Create a registry for Cloud IoT.
*/
public static void createRegistry(String cloudRegion, String projectId, String registryName, String pubsubTopicPath) throws GeneralSecurityException, IOException {
GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init).setApplicationName(APP_NAME).build();
final String projectPath = "projects/" + projectId + "/locations/" + cloudRegion;
final String fullPubsubPath = "projects/" + projectId + "/topics/" + pubsubTopicPath;
DeviceRegistry registry = new DeviceRegistry();
EventNotificationConfig notificationConfig = new EventNotificationConfig();
notificationConfig.setPubsubTopicName(fullPubsubPath);
List<EventNotificationConfig> notificationConfigs = new ArrayList<EventNotificationConfig>();
notificationConfigs.add(notificationConfig);
registry.setEventNotificationConfigs(notificationConfigs);
registry.setId(registryName);
DeviceRegistry reg = service.projects().locations().registries().create(projectPath, registry).execute();
System.out.println("Created registry: " + reg.getName());
}
use of com.google.api.services.cloudiot.v1.model.DeviceRegistry in project java-docs-samples by GoogleCloudPlatform.
the class DeviceRegistryExample method getRegistry.
// [END iot_get_device_state]
// [START iot_get_registry]
/**
* Retrieves registry metadata from a project. *
*/
public static DeviceRegistry getRegistry(String projectId, String cloudRegion, String registryName) throws GeneralSecurityException, IOException {
GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init).setApplicationName(APP_NAME).build();
final String registryPath = String.format("projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName);
return service.projects().locations().registries().get(registryPath).execute();
}
use of com.google.api.services.cloudiot.v1.model.DeviceRegistry in project java-docs-samples by GoogleCloudPlatform.
the class DeviceRegistryExample method listRegistries.
// [END iot_get_device_configs]
// [START iot_list_registries]
/**
* Lists all of the registries associated with the given project.
*/
public static void listRegistries(String projectId, String cloudRegion) throws GeneralSecurityException, IOException {
GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init).setApplicationName(APP_NAME).build();
final String projectPath = "projects/" + projectId + "/locations/" + cloudRegion;
List<DeviceRegistry> registries = service.projects().locations().registries().list(projectPath).execute().getDeviceRegistries();
if (registries != null) {
System.out.println("Found " + registries.size() + " registries");
for (DeviceRegistry r : registries) {
System.out.println("Id: " + r.getId());
System.out.println("Name: " + r.getName());
if (r.getMqttConfig() != null) {
System.out.println("Config: " + r.getMqttConfig().toPrettyString());
}
System.out.println();
}
} else {
System.out.println("Project has no registries.");
}
}
Aggregations