标签: azure-java-sdk

将 Azure 服务总线与 Android 连接

我编写了一个简单的 java 程序(jdk 1.7),它列出了我所有的服务总线主题并将每个主题的名称打印到标准输出:

         try {

         String namespace = "myservicebus"; // from azure portal
         String issuer = "owner";  // from azure portal
         String key = "asdjklasdjklasdjklasdjklasdjk";  // from azure portal

         Configuration config = ServiceBusConfiguration.configureWithWrapAuthentication(
                namespace, 
                issuer,
                key, 
                ".servicebus.windows.net", 
                "-sb.accesscontrol.windows.net/WRAPv0.9"); 

        ServiceBusContract service = ServiceBusService.create(config);
        ListTopicsResult result = service.listTopics();
        List<TopicInfo> infoList = result.getItems();
        for(TopicInfo info : infoList){
            System.out.println( info.getPath());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

现在,我试图在一个简单的 android 项目(Android 4.2)中运行这个例子,但它不起作用。运行时总是抛出以下错误:

java.lang.RuntimeException: Service or property not registered:  com.microsoft.windowsazure.services.serviceBus.ServiceBusContract
Run Code Online (Sandbox Code Playgroud)

有没有人成功建立了从 android 设备(或模拟器)到 azure …

azure azure-java-sdk

5
推荐指数
1
解决办法
1576
查看次数

Azure Functions with java - 如何获取在函数中写入的日志?

我已经在 Azure 中使用 Java 部署了一个队列触发的 azure 函数。我添加logback-classiclombokpom.xml日志记录。但日志不会显示在函数monitor > invocation detailslog-streaming service入口门户上。但是我可以看到用context.getLogger(). 使用 logback logger 的日志编写器不可见。请让我知道如何在函数调用中检查我的日志。

以下是队列触发的 azure 函数句柄

public class QueueHandlerFunction {

  @FunctionName("queuetriggertest")
  public void queueMessageHandler(@QueueTrigger(name = "msg",
      queueName = "my-test-queue", connection = "MyQStorage") final String payload,
      final ExecutionContext context) {

    //Logs with this logger is visible
    context.getLogger().info("Received Message From my-test-queue : " + payload);

    MySampleService.handleQueueMessage(payload);
  }
}
Run Code Online (Sandbox Code Playgroud)

以下是MySampleService带有 lombok 记录器的类

@Slf4j
public class MySampleService { …
Run Code Online (Sandbox Code Playgroud)

java azure azure-java-sdk azure-functions

5
推荐指数
1
解决办法
2512
查看次数

Listing blobs in Azure Blobstorage using Azure Java SDK V12 and ListBlobs() is extremely slow

I need to list all of the blobs in an Azure Blobstorage container. The container has circa 200,000~ blobs in it, and I'm looking to obtain the blob name, the last modified date, and the blob size.

Following the documentation for the Azure Java SDK V12, the following code should work:

BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(AzureBlobConnectionString).buildClient();
String containerName = "container1";
BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(containerName);
System.out.println("\nListing blobs...");

// List the blob(s) in the container.
for (BlobItem blobItem : containerClient.listBlobs()) {
  System.out.println("\t" …
Run Code Online (Sandbox Code Playgroud)

java azure azure-java-sdk azure-blob-storage

5
推荐指数
1
解决办法
487
查看次数

使用具有有限堆的 azure-sdk-for-java 上传大文件

我们正在开发需要使用 Azure 作为文件内容存储的文档微服务。Azure Block Blob 似乎是一个合理的选择。文档服务的堆限制为 512MB ( -Xmx512m)。

我没有成功地使用有限的堆上传流式文件azure-storage-blob:12.10.0-beta.1(也在 上进行了测试12.9.0)。

尝试了以下方法:

  1. 使用从文档中复制粘贴BlockBlobClient
BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient("file").getBlockBlobClient();

File file = new File("file");

try (InputStream dataStream = new FileInputStream(file)) {
  blockBlobClient.upload(dataStream, file.length(), true /* overwrite file */);
}
Run Code Online (Sandbox Code Playgroud)

结果: java.io.IOException: mark/reset not supported - 即使文件输入流报告此功能不受支持,SDK 也会尝试使用标记/重置。

  1. 添加BufferedInputStream以减轻标记/重置问题(根据建议):
BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient("file").getBlockBlobClient();

File file = new File("file");

try (InputStream dataStream = new BufferedInputStream(new FileInputStream(file))) {
  blockBlobClient.upload(dataStream, file.length(), true /* overwrite …
Run Code Online (Sandbox Code Playgroud)

java azure azure-storage-blobs azure-java-sdk azure-sdk-for-java

5
推荐指数
1
解决办法
796
查看次数

Azure documentDB - 具有指定 ID 或名称的资源已存在

在我的应用程序的 Azure Cosmo DocumentDB 中,出现以下错误

2018-03-27 14:42:057 错误 chmsCosmosDBFruiteService - 无法将 Fruites 添加到客户参考:11416e34-3620-45a4-b3be-b845bbf41762
消息:{“错误”:[“具有指定 id 或名称的资源已存在。”] ActivityId:1b70b944-d581-4640-8785-819400433bb4,请求URI:/apps/8d13f597-c7e4-4d60-8713-8a0e9abaa9ac/services/ce0d287f-0125-482b-b32c-22108b5b0ed3/partition s/42c80a49-8042-4032-8cfd -9937ecea8dcc/replicas/131662740073245648p,RequestStats:,SDK:Microsoft.Azure.Documents.Common/1.21.0.0,StatusCode:冲突2018-03-27 14:42:058错误chmaeGlobalExceptionHandler - 异常:类org.apache.catalina.connector .ClientAbortException 消息:java.io.IOException:现有连接被远程主机强制关闭 2018-03-27 14:42:058 警告 oswsmmaExceptionHandlerExceptionResolver - 无法调用 @ExceptionHandler 方法:public java.util.Map com.hm。 myfeed.api.exception.GlobalExceptionHandler.handleException(java.lang.Exception,org.springframework.web.context.request.WebRequest,javax.servlet.http.HttpServletRequest)org.apache.catalina.connector.ClientAbortException:java.io。 IOException:远程主机在 org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:356) 处强制关闭了 org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:815) 处的现有连接在 org.apache.catalina.connector.OutputBuffer.append(OutputBuffer.java:720) 在 org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:391) 在 org.apache.catalina.connector.OutputBuffer.write (OutputBuffer.java:369)在org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96)在org.springframework.security.web.util.OnCommitedResponseWrapper $ SaveContextServletOutputStream.write(OnCommitedResponseWrapper.java:639)

我有点不明白这一点。异常发生在代码中,该代码首先检查集合是否存在(存在),然后检查是否不创建它。显然创建将失败,集合存在!

创建函数

try {
    fruitesDocument = documentClient.createDocument(getCollectionLink(), fruitesDocument , null, false).getResource();
} catch (DocumentClientException e) {
    LOG.error("Could not add fruits for Customer Reference: " + fruitesModel.getId() + "  " + e.getMessage()); …
Run Code Online (Sandbox Code Playgroud)

azure document-database azure-java-sdk azure-cosmosdb

5
推荐指数
1
解决办法
7407
查看次数

Azure存储Java API:帐户不支持HTTP

我正在尝试使用Azure存储Java API来检查存储容器是否存在,并且我看到以下异常.任何想法意味着什么?

ERROR ~ com.microsoft.azure.storage.StorageException: The account being accessed does not support http.
105448         at com.microsoft.azure.storage.StorageException.translateFromHttpStatus(StorageException.java:211)
105449         at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:172)
105450         at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:306)
105451         at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:177)
105452         at com.microsoft.azure.storage.blob.CloudBlobContainer.exists(CloudBlobContainer.java:749)
105453         at com.microsoft.azure.storage.blob.CloudBlobContainer.exists(CloudBlobContainer.java:736)
105454         at com.microsoft.azure.storage.blob.CloudBlobContainer.exists(CloudBlobContainer.java:710)
105455         at com.scalegrid.cloudconnector.azure.AzureStorageClient.createContainerIfItDoesntExist(AzureStorageClient.java:255)
105456         at jobs.azurearm.machinepool.CreateCloudEntity.runStep(CreateCloudEntity.java:114)
105457         at jobs.Utils.ActionExecutor.<init>(ActionExecutor.java:84)
105458         at controllers.Clouds.createMachinePoolForAzureARM(Clouds.java:879)
105459         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
105460         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
105461         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
105462         at java.lang.reflect.Method.invoke(Method.java:497)
105463         at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
105464         at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
105465         at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
105466         at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
105467         at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
105468         at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:257)
105469 …
Run Code Online (Sandbox Code Playgroud)

java azure azure-storage azure-java-sdk

4
推荐指数
1
解决办法
4290
查看次数

插入新文档时未运行 Cosmos Db 触发器

我正在使用 Azure Cosmos DB。我在 Azure 门户中创建了一个简单的触发器,如下所示:

在此处输入图片说明

  var context = getContext();
  var request = context.getRequest();

  // item to be created in the current operation
  var itemToCreate = request.getBody();
  itemToCreate["address"] = "test";

  // update the item that will be created
  request.setBody(itemToCreate);
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我插入新文档时没有触发这个触发器。我还尝试将“触发器类型”设置为“发布”。我错过了什么吗?

java azure azure-java-sdk azureportal azure-cosmosdb

3
推荐指数
1
解决办法
892
查看次数

Azure java:找不到指定的签名标识符的 SAS 标识符

我正在使用 Java SDK 来创建 SAS 来访问 blob。这是代码:

SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
policy.setPermissionsFromString("r");
Calendar date = Calendar.getInstance();
Date expire = new Date(date.getTimeInMillis() + (expirationMinutes * 60000));
Date start = new Date(date.getTimeInMillis());
policy.setSharedAccessExpiryTime(expire);
policy.setSharedAccessStartTime(start);
return blob.getUri().toString()+"?"+blob.generateSharedAccessSignature(policy, externalFileName);
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用 url 访问 blob 时,我收到此错误:

<Error>
<Code>AuthenticationFailed</Code>
<Message>
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:f1f169d2-0001-003f-115a-3be1d6000000 Time:2016-11-10T13:57:14.6192554Z
</Message>
<AuthenticationErrorDetail>
SAS identifier cannot be found for specified signed identifier
</AuthenticationErrorDetail>
</Error>
Run Code Online (Sandbox Code Playgroud)

我在 NET …

java azure azure-storage-blobs azure-java-sdk

2
推荐指数
1
解决办法
1017
查看次数

Azure Java SDK - Azure 身份验证对象 - 到期和处理

我正在尝试列出给定订阅的存储帐户,并尝试拉取订阅的所有 blob 端点。

它的完成方式如下。

一种。使用 subscriptionId 与 Azure.Authenticated 对象创建缓存。这个基本上是为了复用,用于后续业务流程中的sdk api调用

湾 如果上述缓存中没有subscriptionid,则按如下方式创建Azure.Authenticated 对象,并将其放入缓存中

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
    subscription.getClientId(),
    subscription.getTenantId(),
    subscription.getKey(),
    subscription.getEnvironmentType().getEnvironment());

Azure.Authenticated = Azure.configure()
    .withLogLevel(LogLevel.NONE)
    .authenticate(credentials);
Run Code Online (Sandbox Code Playgroud)

C。使用订阅 ID 获取 Azure 对象

azure = authenticatedClient.withSubscription(subscription.getSubscriptionId());
Run Code Online (Sandbox Code Playgroud)

d. 使用 storageAccounts 列表 API 对给定订阅的所有存储帐户进行分页和列出。

try {
              PagedList<StorageAccount> strgAccList = azure.storageAccounts().list();
          boolean hasNextPage = null != strgAccList.currentPage();
          int pageCount = 0;
          if (hasNextPage) {
            while (hasNextPage) {
              ++pageCount;
              Page<StorageAccount> resourcePage = strgAccList.currentPage();
              Iterator<StorageAccount> it = resourcePage.items().iterator();
              while (it.hasNext()) {
                StorageAccount storageAccount = it.next();
                storageAccounts.put(storageAccount.name(), …
Run Code Online (Sandbox Code Playgroud)

java azure azure-java-sdk azure-storage-account azure-sdk

1
推荐指数
1
解决办法
65
查看次数