小编chr*_*ris的帖子

Azure功能 - 限制并行执行

是否可以限制并行运行的最大函数数量?

我阅读了文档并发现了这个:

当多个触发事件发生得比单线程函数运行时可以处理它们更快时,运行时可以并行多次调用该函数.

如果功能应用程序正在使用消费托管计划,则功能应用程序可以自动扩展.功能应用程序的每个实例,无论应用程序是在消费托管计划上运行还是在常规App Service托管计划上运行,都可以使用多个线程并行处理并发函数调用.

每个函数应用程序实例中的最大并发函数调用数根据所使用的触发器类型以及函数应用程序中其他函数使用的资源而有所不同.

https://docs.microsoft.com/en-gb/azure/azure-functions/functions-reference#parallel-execution

我正在使用带有Event Hub输入绑定的App Service计划上的Function,并且在我的Function App中只有一个Function.如果我不能限制它,有谁知道这种设置的并发函数调用的最大数量是多少?

azure azure-functions

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

Postgres Npgsql连接池

我想在Postgres使用Npgsql时更好地理解连接池.(http://www.npgsql.org/)

当我使用连接字符串时:

UserID = root; Password = myPassword; Host = localhost; Port = 5432; Database = myDataBase; Pooling = true; Min Pool Size = 0; Max Pool Size = 100;

"Pooling"将在哪里举行?在我的应用程序服务器上或数据库上?

当我调用connection.Open()时,会发生什么?如果存在连接,则从池中获取连接,如果不存在,则创建池?

关于连接池的任何其他一般信息将不胜感激.

谢谢.

postgresql npgsql

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

从 IActionResult 响应中删除空值

我想设置一个全局设置,以便null在从我的任何 HTTP 函数返回的任何响应中不返回属性。

例子:

public class User
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

[FunctionName("HttpTriggeredFunction")]
public async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
    ILogger log)
{
    var user = new User
    {
        Id = 1,
        FirstName = "Chris",
        LastName = null
    };

    return new OkObjectResult(user);
}
Run Code Online (Sandbox Code Playgroud)

返回:

{
    "id": 1,
    "firstName": "Chris",
    "lastName": null
}
Run Code Online (Sandbox Code Playgroud)

在上面的例子中,我不想lastName在响应中返回。

我知道您可以执行以下操作: …

c# azure json.net azure-functions

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

向同一个接口注册多个实现

我有一个BlobStorageRepository类用于与 Azure blob 存储交互。它实现一个接口IBlobStorageRepository

我需要使用两个实例,BlobStorageRepository但它们使用不同的凭据进行设置:

在我的Startup.cs

// Normal storage
var storageCredentials = new StorageCredentials(_appSettings.BlobStorageAccountName, _appSettings.BlobStorageAccountKey);
var cloudBlobStorageAccount = new CloudStorageAccount(storageCredentials, true);
var cloudBlobClient = cloudBlobStorageAccount.CreateCloudBlobClient();
var blobRepository = new BlobStorageRepository(cloudBlobClient);

// Quarantine storage
var quarantineStorageCredentials = new StorageCredentials(_appSettings.QuarantineBlobStorageAccountName, _appSettings.QuarantineBlobStorageAccountKey);
var quarantineCloudBlobStorageAccount = new CloudStorageAccount(quarantineStorageCredentials, true);
var quarantineCloudBlobClient = quarantineCloudBlobStorageAccount.CreateCloudBlobClient();
var quarantineBlobRepository = new BlobStorageRepository(quarantineCloudBlobClient);

services.AddSingleton<IBlobStorageRepository>(blobRepository);
services.AddSingleton<IBlobStorageRepository>(quarantineBlobRepository);
Run Code Online (Sandbox Code Playgroud)

如何配置上述内容,以便可以解析类中的依赖项并获取两个不同的实例,即:

private readonly IBlobStorageRepository _blobStorageRepository;
private readonly IBlobStorageRepository _quarantineBlobStorageRepository;

public DocumentService(IBlobStorageRepository blobStorageRepository, IBlobStorageRepository quarantineBlobStorageRepository)
{
    _blobStorageRepository …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection .net-core asp.net-core-webapi

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

Azure Functions - 跨函数应用共享代码

有没有办法在 Azure 中的两个不同函数应用之间共享公共代码?

我知道可以在同一个 Function App 下的两个函数之间共享代码,如下所示:

#load "../Shared/ServiceLogger.csx"
Run Code Online (Sandbox Code Playgroud)

但我想在两个不同的函数之间共享日志代码,每个函数都在它自己的函数应用程序下。函数在两个不同的函数应用程序下的原因是我需要一个在消费计划上运行,另一个在应用服务计划上运行,除非有另一种方法可以做到这一点?

azure azure-functions

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

从 Flurl HttpResponseMessage 获取响应正文

我正在对正在运行的 Rest API 进行一些自动监视,我需要从 HttpResponseMessage 对象中检索响应正文。我使用 Flurl http:https ://fluurl.dev/docs/fluent-http/

我知道如何通过在 http 请求的末尾添加“.RecieveSomeForm()”来检索响应主体,但我还需要获取响应标头,因为来自 Rest API 的错误代码作为标头发回。我的问题是 - 据我所知和我尝试过的 - 它只是我可以从中检索标题的 HttpResponseMessage 对象。所以问题是:如何在仍然能够检索标题以进行错误记录的同时从 HttpResponseMessage 中获取响应体?

using (var cli = new FlurlClient(URL).EnableCookies())
{

//get response body - var is set to string and has only response body

var AsyncResponse = await cli.WithHeader("some header").Request("some end point").AllowAnyHttpStatus().PostJsonAsync(some body).ReceiveString();
Console.WriteLine(AsyncResponse);



//get headers - var is set to HttpResponseMessage

var AsyncResponse = await cli.WithHeader("some header").Request("some end point").AllowAnyHttpStatus().PostJsonAsync(some body);
Console.WriteLine(AsyncResponse.Headers);

}
Run Code Online (Sandbox Code Playgroud)

c# flurl

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

从另一个Azure功能启动Azure功能的最佳实践

我有一个场景,我有2个函数,比如函数A和函数B.

目前,功能A和功能B都具有相同的逻辑,用于记录失败的活动,其中元数据记录到表存储,JSON记录到Blob存储.

编辑 - >功能A和功能B在两个不同的功能应用程序(预期)中.功能A在消费计划上,功能B在应用服务计划上.

第一个问题 - 创建一个Function C并从A和B中获取失败的活动记录逻辑并将其放入C中是否有意义?

这消除了代码重复,逻辑在一个地方,更容易管理.

第二个问题 - 从A和B调用函数C的最佳方法是什么?

我在这里读到,最好使用存储队列或服务总线进行功能之间的交叉通信.我遇到的问题是 - 我需要存储的JSON在大多数情况下会超过256KB,所以我不能把它放在一个队列来触发一个Function.

那么,函数C可以是一个HTTP触发器吗?我发送一个请求,其中包含从函数A和B通过HTTP登录所需的所有相关信息?

有什么理由不这样做吗?

非常感谢.

c# http azure azure-functions

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

在构造函数中向 ArrayList 添加新对象

我正在尝试将新创建的对象添加到类的构造函数中的 ArrayList。新对象是在 main 方法的另一个类中创建的。

主要方法:

public static void main(String[] args) {
    // TODO code application logic here
    Player p1 = new Player("Peter");
}
Run Code Online (Sandbox Code Playgroud)

我的播放器类:

public class Player {

protected static int age;
protected static String name;
protected static ArrayList players = new ArrayList();

Player(String aName) {
    
    name = aName;
    age = 15;
    players.add(new Player()); // i know this doesn't work but trying along these lines
    
   }
}
Run Code Online (Sandbox Code Playgroud)

java class arraylist object

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

用forkJoin进行条件可观察

在某些情况下,我可能需要或不需要将可观察值添加到列表中。然后,我要forkJoin使用我拥有的可观察对象,以便在所有数据可用后就可以加载页面。

let observables: Observable<any>[] = [];

observables.push(this.taskService.getStep(this.housingTransactionId, this.task.stageReferenceId, this.task.stepReferenceId));

if (this.task.associatedChatThreadId) {
    observables.push(this.messageHubService.getChatThread(this.housingTransactionId, this.task.associatedChatThreadId));
}

if (this.task.associatedDocuments && this.task.associatedDocuments.length > 0) {
    this.task.associatedDocuments.forEach(documentId => {
        observables.push(this.documentHubService.getDocumentProperties(this.housingTransactionId, documentId));
    });
}

Observable.forkJoin(observables)
    .subscribe(([step, chatThread, ...documents]) => {

        this.step = step;           
        this.chatThread = chatThread;           
        this.documents = documents;

        this.isPageLoading = false;

    }, error => {
        this.isPageLoading = false;
        console.log(error);
    });
Run Code Online (Sandbox Code Playgroud)

我得到的问题是,如果我没有this.task.associatedChatThreadId,那么可观察对象将不会添加到列表中,并且在forkJoin执行时,...documents它们将位于chatThreadSubscribe方法中属性的位置(好吧,第一个文档! )。

有没有办法确保来自a的响应的定位forkJoin?还是我/我可以使用其他方法?

javascript observable rxjs typescript angular

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