提交 f39f31c2 编写于 作者: 麦壳饼's avatar 麦壳饼

增加RabbitMQ调整url连接字符串的问题 调整docker-compose 相关问题

上级 b0808ead
...@@ -339,3 +339,6 @@ ASALocalRun/ ...@@ -339,3 +339,6 @@ ASALocalRun/
/IoTSharp/DiskQuue-log.iotsharp /IoTSharp/DiskQuue-log.iotsharp
/zk-single-kafka-single /zk-single-kafka-single
/postgresql /postgresql
/data
/data
/rabbitmq
using IoTSharp.Data; using DotNetCore.CAP;
using IoTSharp.Data;
using IoTSharp.Services; using IoTSharp.Services;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
...@@ -9,6 +10,7 @@ using Microsoft.Extensions.DependencyInjection; ...@@ -9,6 +10,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using MQTTnet.Diagnostics; using MQTTnet.Diagnostics;
using Silkier.Extensions;
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
...@@ -97,5 +99,43 @@ namespace IoTSharp ...@@ -97,5 +99,43 @@ namespace IoTSharp
return externalPath + internalUiRoute; return externalPath + internalUiRoute;
}); });
} }
public static CapOptions UseRabbitMQ(this CapOptions options, Uri url)
{
return options.UseRabbitMQ(opt =>
{
var usr = url.UserInfo?.Split(':');
opt.HostName = url.Host;
opt.UserName = usr?.Length > 0 ? usr[0] : RabbitMQOptions.DefaultUser;
opt.Password = usr?.Length > 1 ? usr[1] : RabbitMQOptions.DefaultPass;
opt.Port = url.Port;
});
}
public static void ConnectionString2Options<T>(this T option ,string _connectionString )
{
_connectionString.Split(';', StringSplitOptions.RemoveEmptyEntries).ForEach(f =>
{
try
{
var opt = f.Split('=');
var pty = option?.GetType().GetProperty(opt[0]);
if (pty.PropertyType == typeof(string))
{
pty.SetValue(option, opt[1]);
}
else if (pty.PropertyType == typeof(int))
{
pty.SetValue(option, int.Parse(opt[1]));
}
else if (pty.PropertyType == typeof(bool))
{
pty.SetValue(option, opt[1]?.ToString().ToLower() == bool.TrueString.ToLower());
}
}
catch (Exception)
{
}
});
}
} }
} }
\ No newline at end of file
...@@ -49,6 +49,8 @@ using EasyCaching.Core.Configurations; ...@@ -49,6 +49,8 @@ using EasyCaching.Core.Configurations;
using Silkier.Extensions; using Silkier.Extensions;
using Maikebing.Data.Taos; using Maikebing.Data.Taos;
using Dynamitey; using Dynamitey;
using DotNetCore.CAP;
using RabbitMQ.Client;
namespace IoTSharp namespace IoTSharp
{ {
...@@ -138,13 +140,14 @@ namespace IoTSharp ...@@ -138,13 +140,14 @@ namespace IoTSharp
services.AddMqttClient(settings.MqttClient); services.AddMqttClient(settings.MqttClient);
services.AddSingleton<RetainedMessageHandler>(); services.AddSingleton<RetainedMessageHandler>();
var healthChecks = services.AddHealthChecks() var healthChecks = services.AddHealthChecks()
.AddNpgSql(Configuration["IoTSharp"], name: "PostgreSQL") .AddNpgSql(Configuration.GetConnectionString("IoTSharp"), name: "PostgreSQL")
.AddDiskStorageHealthCheck(dso => .AddDiskStorageHealthCheck(dso =>
{ {
System.IO.DriveInfo.GetDrives().Select(f=>f.Name).Distinct().ToList().ForEach(f => dso.AddDrive(f, 1024)); System.IO.DriveInfo.GetDrives().Select(f=>f.Name).Distinct().ToList().ForEach(f => dso.AddDrive(f, 1024));
}, name: "Disk Storage"); }, name: "Disk Storage");
services.AddHealthChecksUI().AddPostgreSqlStorage(Configuration.GetConnectionString("IoTSharp")); services.AddHealthChecksUI(cfg=>cfg.AddHealthCheckEndpoint("IoTSharp", "http://iotsharp/healthz"))
.AddPostgreSqlStorage(Configuration.GetConnectionString("IoTSharp"));
services.AddSilkierQuartz(opt=> services.AddSilkierQuartz(opt=>
{ {
//opt.Add("quartz.serializer.type", "json"); //opt.Add("quartz.serializer.type", "json");
...@@ -197,8 +200,8 @@ namespace IoTSharp ...@@ -197,8 +200,8 @@ namespace IoTSharp
break; break;
case TelemetryStorage.Taos: case TelemetryStorage.Taos:
services.AddSingleton<IStorage, TaosStorage>(); services.AddSingleton<IStorage, TaosStorage>();
services.AddObjectPool(()=> new TaosConnection(settings.ConnectionStrings["Taos"])); services.AddObjectPool(()=> new TaosConnection(settings.ConnectionStrings["TelemetryStorage"]));
healthChecks.AddTDengine(Configuration.GetConnectionString("Taos")); healthChecks.AddTDengine(Configuration.GetConnectionString("TelemetryStorage"));
break; break;
default: default:
break; break;
...@@ -232,7 +235,8 @@ namespace IoTSharp ...@@ -232,7 +235,8 @@ namespace IoTSharp
{ {
case EventBusMQ.RabbitMQ: case EventBusMQ.RabbitMQ:
x.UseRabbitMQ(Configuration.GetConnectionString("EventBusMQ")); x.UseRabbitMQ(new Uri( Configuration.GetConnectionString("EventBusMQ")));
//amqp://guest:guest@localhost:5672
healthChecks.AddRabbitMQ(Configuration.GetConnectionString("EventBusMQ"), name: "EventBusMQ"); healthChecks.AddRabbitMQ(Configuration.GetConnectionString("EventBusMQ"), name: "EventBusMQ");
break; break;
case EventBusMQ.Kafka: case EventBusMQ.Kafka:
...@@ -305,22 +309,23 @@ namespace IoTSharp ...@@ -305,22 +309,23 @@ namespace IoTSharp
}); });
app.UseSwaggerUi3(); app.UseSwaggerUi3();
app.UseOpenApi(); app.UseOpenApi();
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseResponseCompression(); // No need if you use IIS, but really something good for Kestrel!
app.UseHealthChecks("/healthz", new HealthCheckOptions app.UseHealthChecks("/healthz", new HealthCheckOptions
{ {
Predicate = _ => true, Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse ResponseWriter = (httpContext, report) =>
{
return UIResponseWriter.WriteHealthCheckUIResponse(httpContext, report);
}
}); });
app.UseHealthChecksUI(); app.UseHealthChecksUI();
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseResponseCompression(); // No need if you use IIS, but really something good for Kestrel!
} }
} }
} }
\ No newline at end of file
...@@ -7,34 +7,16 @@ ...@@ -7,34 +7,16 @@
} }
}, },
"ConnectionStrings": { "ConnectionStrings": {
"IoTSharp": "Server=localhost;Database=IoTSharp;Username=postgres;Password=future;", "IoTSharp": "Server=pgsql;Database=IoTSharp;Username=postgres;Password=future;",
"EventBusStore": "Server=localhost;Database=IoTSharp;Username=postgres;Password=future;", "EventBusStore": "mongodb://root:kissme@mongodb:27017",
"TelemetryStorage": "Server=localhost;Database=IoTSharp;Username=postgres;Password=future;", "TelemetryStorage": "DataSource=taos;DataBase=IoTSharp;Username=root;Password=taosdata;Port=6030",
"EventBusMQ": "127.0.0.1" "EventBusMQ": "amqp://root:kissme@rabbitmq:5672"
},
"MqttBroker": {
"Port": 7777
}, },
"JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme", "JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme",
"JwtExpireHours": 24, "JwtExpireHours": 24,
"JwtIssuer": "IoTSharp.Net", "JwtIssuer": "IoTSharp.Net",
"JwtAudience": "IoTSharp.Net", "JwtAudience": "IoTSharp.Net",
"EventBusStore": "PostgreSql", "EventBusStore": "MongoDB",
"EventBusMQ": "ZeroMQ", "EventBusMQ": "RabbitMQ",
"TelemetryStorage": "Sharding", "TelemetryStorage": "Taos"
"CachingUseIn": "InMemory",
"CachingUseRedisHosts": "127.0.0.1:6379;127.0.0.2:6379",
"Sharding": {
"DatabaseType": "PostgreSql",
"ExpandByDateMode": "PerMonth"
},
"NetMQ": {
"Enable": "true",
"SubscriberAddress": "tcp://127.0.0.1:5556",
"PublisherAddress": "tcp://127.0.0.1:5557"
},
"ZMQOption": {
"SendAddress": "tcp://127.0.0.1:5556",
"ReceiveAddress": "tcp://127.0.0.1:5557"
}
} }
\ No newline at end of file
...@@ -12,22 +12,16 @@ ...@@ -12,22 +12,16 @@
"JwtExpireHours": 24, "JwtExpireHours": 24,
"JwtIssuer": "IoTSharp.Net", "JwtIssuer": "IoTSharp.Net",
"JwtAudience": "IoTSharp.Net", "JwtAudience": "IoTSharp.Net",
"HealthChecks-UI": { "HealthChecksUI": {
"HealthChecks": [ "HealthChecks": [
{ {
"Name": "HTTP-Api-Basic", "Name": "IoTSharp",
"Uri": "http://localhost/healthz" "Uri": "http://iotsharp/healthz"
} }
], ],
"Webhooks": [ "Webhooks": [
{
"Name": "",
"Uri": "",
"Payload": "",
"RestoredPayload": ""
}
], ],
"EvaluationTimeOnSeconds": 10, "EvaluationTimeinSeconds": 10,
"MinimumSecondsBetweenFailureNotifications": 60 "MinimumSecondsBetweenFailureNotifications": 60
}, },
"AllowedHosts": "*" "AllowedHosts": "*"
......
...@@ -8,28 +8,15 @@ ...@@ -8,28 +8,15 @@
}, },
"ConnectionStrings": { "ConnectionStrings": {
"IoTSharp": "Server=pgsql;Database=IoTSharp;Username=postgres;Password=future;", "IoTSharp": "Server=pgsql;Database=IoTSharp;Username=postgres;Password=future;",
"EventBusStore": "Server=pgsql;Database=IoTSharp;Username=postgres;Password=future;", "EventBusStore": "mongodb://root:kissme@mongodb:27017",
"TelemetryStorage": "Server=pgsql;Database=IoTSharp;Username=postgres;Password=future;", "TelemetryStorage": "DataSource=taos;DataBase=IoTSharp;Username=root;Password=taosdata;Port=6030",
"EventBusMQ": "127.0.0.1" "EventBusMQ": "amqp://root:kissme@rabbitmq:5672"
}, },
"JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme", "JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme",
"JwtExpireHours": 24, "JwtExpireHours": 24,
"JwtIssuer": "IoTSharp.Net", "JwtIssuer": "IoTSharp.Net",
"JwtAudience": "IoTSharp.Net", "JwtAudience": "IoTSharp.Net",
"EventBusStore": "PostgreSql", "EventBusStore": "MongoDB",
"EventBusMQ": "ZeroMQ", "EventBusMQ": "RabbitMQ",
"TelemetryStorage": "Sharding", "TelemetryStorage": "Taos"
"Sharding": {
"DatabaseType": "PostgreSql",
"ExpandByDateMode": "PerMonth"
},
"NetMQ": {
"Enable": "true",
"SubscriberAddress": "tcp://127.0.0.1:5556",
"PublisherAddress": "tcp://127.0.0.1:5557"
},
"ZMQOption": {
"SendAddress": "tcp://127.0.0.1:5556",
"ReceiveAddress": "tcp://127.0.0.1:5557"
}
} }
\ No newline at end of file
version: '3.4' version: '3.4'
services: services:
iotsharp: iotsharp:
image: ${DOCKER_REGISTRY-}iotsharp image: ${DOCKER_REGISTRY-}iotsharp
......
...@@ -5,7 +5,7 @@ services: ...@@ -5,7 +5,7 @@ services:
container_name: pgsql container_name: pgsql
restart: always restart: always
volumes: volumes:
- "./postgresql:/var/lib/postgresql/data" - "./data/postgresql:/var/lib/postgresql/data"
environment: environment:
TZ: "Asia/Shanghai" TZ: "Asia/Shanghai"
POSTGRES_USER: postgres POSTGRES_USER: postgres
...@@ -55,10 +55,38 @@ services: ...@@ -55,10 +55,38 @@ services:
networks: networks:
- iotsharp-network - iotsharp-network
rabbitmq:
image: rabbitmq:management
container_name: rabbitmq
restart: always
hostname: mq
ports:
- 15672:15672
- 5672:5672
volumes:
- ./data/rabbitmq:/var/lib/rabbitmq
environment:
- RABBITMQ_DEFAULT_USER=root
- RABBITMQ_DEFAULT_PASS=kissme
networks:
- iotsharp-network
mongodb:
image: mongo:latest
restart: always
container_name: mongodb
volumes:
- ./data/mongodb/db:/data/db
- ./data/mongodb/log:/var/log/mongodb
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: kissme
networks:
- iotsharp-network
networks: networks:
iotsharp-network: iotsharp-network:
driver: bridge driver: bridge
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册