CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Reposted on 2024-08-06
by Ikhtesam Afrin

Original Post

Original - Posted on 2024-04-05
by Ikhtesam Afrin



            
Present in both answers; Present only in the new answer; Present only in the old answer;

I am able to send the message to Service Bus and return a Http response using below code.
```csharp
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Logging; using System.Net; using System.Text.Json.Serialization;
namespace _78837659 { public class Function1 { private readonly ILogger<Function1> _logger; private readonly IPassfortDataService _passfortDataService; private readonly IMyService _myService;
public Function1(ILogger<Function1> logger, IPassfortDataService passfortDataService, IMyService myService) { _logger = logger; _myService = myService; _passfortDataService = passfortDataService; }
[Function("Process-Duplicates")] public async Task<DispatchedMessages> ProcessDataAsync( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "myroute")] HttpRequestData req) { // Process your data await _passfortDataService.ProcessDataAsync();
HttpResponseData response = req.CreateResponse(HttpStatusCode.OK); await response.WriteStringAsync("HTTP response: Message sent");
return new DispatchedMessages() { Messages = _myService.MessagesToBeSent.Select(x => x.ToJson()), HttpResponse = response }; } }
public class DispatchedMessages { [JsonIgnore] [ServiceBusOutput("myqueue", Connection = "ServiceBusConnection")] public IEnumerable<string>? Messages { get; set; }
public HttpResponseData HttpResponse { get; set; }
} } ```
You should have below codes in the mentioned files.
**.csproj**-
```csharp <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> <OutputType>Exe</OutputType> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <RootNamespace>_78837659</RootNamespace> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.20.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.0" /> <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" /> </ItemGroup> <ItemGroup> <None Update="host.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="local.settings.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None> </ItemGroup> <ItemGroup> <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" /> </ItemGroup> </Project> ```
**Program.cs**-
```csharp using _78837659; using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting;
var host = new HostBuilder() .ConfigureFunctionsWorkerDefaults() .ConfigureServices(services => { services.AddApplicationInsightsTelemetryWorkerService(); services.ConfigureFunctionsApplicationInsights(); services.AddSingleton<IPassfortDataService, PassfortDataService>(); services.AddSingleton<IMyService, MyService>(); }) .Build();
host.Run(); ```
I am able to see below response while invoking the URL.
![enter image description here](https://i.imgur.com/YYyrFbS.png)
![enter image description here](https://i.imgur.com/SRp3fjb.png)
I am using the below code to send message to a Service Bus session enabled queue.
```csharp using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Azure.Messaging.ServiceBus;
namespace _78259611 { public static class Function1 { [FunctionName("Function1")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous,"post", Route = null)] HttpRequest req, [ServiceBus("myqueue", Connection = "ServiceBusConnection")] IAsyncCollector<ServiceBusMessage> outputSbQueue, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request.");
string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var message = new ServiceBusMessage(requestBody); message.SessionId = "{session_id}";
// Add message to the session-enabled queue await outputSbQueue.AddAsync(message);
return new OkObjectResult("Message sent successfully."); } } } ```
**.csproj**-
```csharp <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net6.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> <RootNamespace>_78259611</RootNamespace> </PropertyGroup> <ItemGroup> <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.17.4" /> <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.14.0" /> <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.3.0" /> </ItemGroup> <ItemGroup> <None Update="host.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="local.settings.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None> </ItemGroup> </Project> ```
- I am able to receive all the messages in Service Bus queue.
![enter image description here](https://i.imgur.com/wXyP6ko.png)
![enter image description here](https://i.imgur.com/sgd1BU8.png)
![enter image description here](https://i.imgur.com/a90OCve.png)

        
Present in both answers; Present only in the new answer; Present only in the old answer;