Merge pull request #5 from Espent1004/tenantManagerExpansion

Adding the customisationUrl to the tenantManager rather than hardcodi…
This commit is contained in:
Espent1004 2020-02-02 20:00:05 +01:00 committed by GitHub
commit bbc84c6b1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 19 deletions

View File

@ -279,7 +279,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
return channel; return channel;
} }
private async void SendEventToTenant(String content, String id, String eventName) private async void SendEventToTenant(String content, String id, String eventName, String url)
{ {
var temp = new SavedEvent(); var temp = new SavedEvent();
temp.Content = content; temp.Content = content;
@ -290,9 +290,8 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
{ {
try try
{ {
//TODO replace URL with response from tenantmanager
var response = await client.PostAsync( var response = await client.PostAsync(
tenantACustomisationUrl + "api/SavedEvents", url,
new StringContent(myJson, Encoding.UTF8, "application/json")); new StringContent(myJson, Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
_logger.LogInformation("----- Event sent to tenant{@id} -----", id); _logger.LogInformation("----- Event sent to tenant{@id} -----", id);
@ -305,12 +304,12 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
} }
} }
private async Task<Boolean> IsEventCustomised(String eventName, int tenantId) private async Task<String> GetCustomisation(String eventName, int tenantId)
{ {
CustomisationInfo customisationInfo = new CustomisationInfo(); CustomisationInfo customisationInfo = new CustomisationInfo();
customisationInfo.EventName = eventName; customisationInfo.EventName = eventName;
customisationInfo.TenantId = tenantId; customisationInfo.TenantId = tenantId;
Boolean isCustomised = false; String customisationUrl = null;
var builder = new UriBuilder(tenantManagerUrl + "api/Customisations/IsCustomised"); var builder = new UriBuilder(tenantManagerUrl + "api/Customisations/IsCustomised");
builder.Port = -1; builder.Port = -1;
@ -327,8 +326,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
var response = await client.GetAsync( var response = await client.GetAsync(
url); url);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
isCustomised = customisationUrl = response.Content.ReadAsStringAsync().Result;
JsonConvert.DeserializeObject<Boolean>(response.Content.ReadAsStringAsync().Result);
} }
catch (Exception e) catch (Exception e)
{ {
@ -336,7 +334,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
} }
} }
return isCustomised; return customisationUrl;
} }
private async Task ProcessEvent(string eventName, string message) private async Task ProcessEvent(string eventName, string message)
@ -369,14 +367,13 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
var eventType = _subsManager.GetEventTypeByName(eventName); var eventType = _subsManager.GetEventTypeByName(eventName);
var integrationEvent = JsonConvert.DeserializeObject(message, eventType); var integrationEvent = JsonConvert.DeserializeObject(message, eventType);
IntegrationEvent evt = (IntegrationEvent) integrationEvent; IntegrationEvent evt = (IntegrationEvent) integrationEvent;
if (IsEventCustomised(eventName, evt.TenantId).Result) //TODO fix tenantId part of request var customisationUrl = GetCustomisation(eventName, evt.TenantId).Result;
if (evt.CheckForCustomisation && !String.IsNullOrEmpty(customisationUrl))
{ {
//Checking if event should be sent to tenant, or handled normally //Checking if event should be sent to tenant, or handled normally
if (evt.CheckForCustomisation && evt.TenantId == 1)//TODO use tenantId to choose the correct endpoint to send the event to SendEventToTenant(message, evt.Id.ToString(), eventName,
{ customisationUrl);
SendEventToTenant(message, evt.Id.ToString(), eventName); break;
break;
}
} }
var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(eventType); var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(eventType);

View File

@ -44,16 +44,16 @@ namespace TenantManager.Controllers
// GET: api/Customisations/5 // GET: api/Customisations/5
[HttpGet("isCustomised")] [HttpGet("isCustomised")]
public async Task<ActionResult<Boolean>> IsCustomised(String eventName, int tenantId) public async Task<ActionResult<string>> IsCustomised(String eventName, int tenantId)
{ {
var customisation = await _context.Customisation.Include(c => c.Method).Include(c => c.Tenant).Where(c => c.Method.MethodName.Equals(eventName) && c.TenantId == tenantId).FirstOrDefaultAsync(); var customisation = await _context.Customisation.Include(c => c.Method).Include(c => c.Tenant).Where(c => c.Method.MethodName.Equals(eventName) && c.TenantId == tenantId).FirstOrDefaultAsync();
if (customisation == null) if (customisation == null)
{ {
return false; return NotFound();
} }
return true; return customisation.CustomisationUrl;
} }
// PUT: api/Customisations/5 // PUT: api/Customisations/5

View File

@ -33,8 +33,8 @@ namespace TenantManager.Database
var customisations = new[] var customisations = new[]
{ {
new Customisation {Tenant=tenant1, Method=method1 }, new Customisation {Tenant=tenant1, Method=method1, CustomisationUrl = @"http://tenantacustomisation/api/savedevents"},
new Customisation {Tenant=tenant1, Method=method2} new Customisation {Tenant=tenant1, Method=method2, CustomisationUrl = @"http://tenantacustomisation/api/savedevents"}
}; };
foreach(Customisation c in customisations) foreach(Customisation c in customisations)

View File

@ -9,6 +9,7 @@ namespace TenantManager.Models
public class Customisation public class Customisation
{ {
public int CustomisationId { get; set; } public int CustomisationId { get; set; }
public String CustomisationUrl { get; set; }
//Foreign keys //Foreign keys
public int TenantId { get; set; } public int TenantId { get; set; }